summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
67ecffc)
clock_gettime() of CLOCK_MONOTONIC mimicks better the behavior of a
cycle counter, since it is not affected by NTP major time updates.
Also, now prefix "cycles_t" with a caa_ prefix, so it does not clash
with application namespaces. Anyway, caa_get_cycles() is mostly used in
testing.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ caa_cycles_t time1, time2;
time1 = caa_get_cycles();
loop_sleep(NR_LOOPS);
time1 = caa_get_cycles();
loop_sleep(NR_LOOPS);
int main(int argc, char **argv)
{
unsigned long i;
int main(int argc, char **argv)
{
unsigned long i;
- cycles_t time1, time2;
- cycles_t time_tot = 0;
+ caa_cycles_t time1, time2;
+ caa_cycles_t time_tot = 0;
double cpl;
for (i = 0; i < TESTS; i++) {
double cpl;
for (i = 0; i < TESTS; i++) {
#define NR_READ num_read
#define NR_WRITE num_write
#define NR_READ num_read
#define NR_WRITE num_write
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
void *thr_reader(void *arg)
{
int i, j;
void *thr_reader(void *arg)
{
int i, j;
+ caa_cycles_t time1, time2;
long tidx = (long)arg;
printf("thread_begin %s, tid %lu\n",
long tidx = (long)arg;
printf("thread_begin %s, tid %lu\n",
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
- cycles_t tot_rtime = 0;
- cycles_t tot_wtime = 0;
+ caa_cycles_t tot_rtime = 0;
+ caa_cycles_t tot_wtime = 0;
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
#define NR_READ num_read
#define NR_WRITE num_write
#define NR_READ num_read
#define NR_WRITE num_write
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
void *thr_reader(void *arg)
{
int i, j;
void *thr_reader(void *arg)
{
int i, j;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
void *thr_writer(void *arg)
{
int i, j;
void *thr_writer(void *arg)
{
int i, j;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
- cycles_t tot_rtime = 0;
- cycles_t tot_wtime = 0;
+ caa_cycles_t tot_rtime = 0;
+ caa_cycles_t tot_wtime = 0;
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
#define NR_READ num_read
#define NR_WRITE num_write
#define NR_READ num_read
#define NR_WRITE num_write
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
void *thr_reader(void *arg)
{
int i, j;
struct test_array *local_ptr;
void *thr_reader(void *arg)
{
int i, j;
struct test_array *local_ptr;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
{
int i, j;
struct test_array *new, *old;
{
int i, j;
struct test_array *new, *old;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
- cycles_t tot_rtime = 0;
- cycles_t tot_wtime = 0;
+ caa_cycles_t tot_rtime = 0;
+ caa_cycles_t tot_wtime = 0;
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
#define NR_READ num_read
#define NR_WRITE num_write
#define NR_READ num_read
#define NR_WRITE num_write
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
-static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time;
+static caa_cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time;
void *thr_reader(void *arg)
{
int i, j;
struct test_array *local_ptr;
void *thr_reader(void *arg)
{
int i, j;
struct test_array *local_ptr;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"reader", urcu_get_thread_id());
{
int i, j;
struct test_array *new, *old;
{
int i, j;
struct test_array *new, *old;
+ caa_cycles_t time1, time2;
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
printf("thread_begin %s, tid %lu\n",
"writer", urcu_get_thread_id());
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
pthread_t *tid_reader, *tid_writer;
void *tret;
int i;
- cycles_t tot_rtime = 0;
- cycles_t tot_wtime = 0;
+ caa_cycles_t tot_rtime = 0;
+ caa_cycles_t tot_wtime = 0;
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
if (argc < 2) {
printf("Usage : %s nr_readers nr_writers\n", argv[0]);
#ifndef HAS_CAA_GET_CYCLES
#define HAS_CAA_GET_CYCLES
#ifndef HAS_CAA_GET_CYCLES
#define HAS_CAA_GET_CYCLES
-typedef unsigned long long cycles_t;
-static inline cycles_t caa_get_cycles (void)
+#include <time.h>
+#include <stdint.h>
+
+typedef uint64_t caa_cycles_t;
+
+static inline caa_cycles_t caa_get_cycles (void)
- cycles_t thetime;
- struct timeval tv;
- if (gettimeofday(&tv, NULL) != 0)
- return 0;
- thetime = ((cycles_t)tv.tv_sec) * 1000000ULL + ((cycles_t)tv.tv_usec);
- return (cycles_t)thetime;
+ if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC, &ts)))
+ return -1ULL;
+ return ((uint64_t) ts.tv_sec * 1000000000ULL) + ts.tv_nsec;
}
#endif /* HAS_CAA_GET_CYCLES */
}
#endif /* HAS_CAA_GET_CYCLES */
#include <sys/time.h>
#define HAS_CAA_GET_CYCLES
#include <sys/time.h>
#define HAS_CAA_GET_CYCLES
-typedef unsigned long cycles_t;
+typedef unsigned long caa_cycles_t;
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
asm volatile("mfctl 16, %0" : "=r" (cycles));
return cycles;
asm volatile("mfctl 16, %0" : "=r" (cycles));
return cycles;
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
#define HAS_CAA_GET_CYCLES
#define HAS_CAA_GET_CYCLES
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
- return (cycles_t) mftb();
+ return (caa_cycles_t) mftb();
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
l = mftbl();
cmm_barrier();
if (mftbu() == h)
l = mftbl();
cmm_barrier();
if (mftbu() == h)
- return (((cycles_t) h) << 32) + l;
+ return (((caa_cycles_t) h) << 32) + l;
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
#define HAS_CAA_GET_CYCLES
#define HAS_CAA_GET_CYCLES
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
-static inline cycles_t caa_get_cycles (void)
+static inline caa_cycles_t caa_get_cycles (void)
__asm__ __volatile__("stck %0" : "=m" (cycles) : : "cc", "memory" );
__asm__ __volatile__("stck %0" : "=m" (cycles) : : "cc", "memory" );
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#include <urcu/compiler.h>
#include <urcu/config.h>
#include <urcu/syscall-compat.h>
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
| (((unsigned long long)__d) << 32); \
} while(0)
| (((unsigned long long)__d) << 32); \
} while(0)
-typedef unsigned long long cycles_t;
+typedef uint64_t caa_cycles_t;
-static inline cycles_t caa_get_cycles(void)
+static inline caa_cycles_t caa_get_cycles(void)
rdtscll(ret);
return ret;
rdtscll(ret);
return ret;