| 1 |
/* -*- linux-c -*- |
| 2 |
* Stat Runtime Functions |
| 3 |
* Copyright (C) 2012 Red Hat Inc. |
| 4 |
* |
| 5 |
* This file is part of systemtap, and is free software. You can |
| 6 |
* redistribute it and/or modify it under the terms of the GNU General |
| 7 |
* Public License (GPL); either version 2, or (at your option) any |
| 8 |
* later version. |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef _STAPDYN_STAT_RUNTIME_H_ |
| 12 |
#define _STAPDYN_STAT_RUNTIME_H_ |
| 13 |
|
| 14 |
#include <pthread.h> |
| 15 |
#include <unistd.h> |
| 16 |
#include <sched.h> |
| 17 |
|
| 18 |
#include "offptr.h" |
| 19 |
|
| 20 |
#define STAT_LOCK(sd) do {} while (0) |
| 21 |
#define STAT_UNLOCK(sd) do {} while (0) |
| 22 |
|
| 23 |
static int STAT_GET_CPU(void) |
| 24 |
{ |
| 25 |
return _stp_runtime_get_data_index(); |
| 26 |
} |
| 27 |
|
| 28 |
#define STAT_PUT_CPU() do {} while (0) |
| 29 |
|
| 30 |
|
| 31 |
/** Stat struct. Maps do not need this */ |
| 32 |
typedef struct _Stat { |
| 33 |
struct _Hist hist; |
| 34 |
|
| 35 |
/* aggregated data */ |
| 36 |
offptr_t oagg; |
| 37 |
|
| 38 |
/* The stat data is a "per-cpu" array. */ |
| 39 |
offptr_t osd[]; |
| 40 |
} *Stat; |
| 41 |
|
| 42 |
static Stat _stp_stat_alloc(size_t stat_data_size) |
| 43 |
{ |
| 44 |
int i; |
| 45 |
void *mem; |
| 46 |
Stat st; |
| 47 |
|
| 48 |
size_t stat_size = sizeof(struct _Stat) |
| 49 |
+ sizeof(offptr_t) * _stp_runtime_num_contexts; |
| 50 |
|
| 51 |
size_t total_size = stat_size + |
| 52 |
stat_data_size * (_stp_runtime_num_contexts + 1); |
| 53 |
|
| 54 |
if (stat_data_size < sizeof(stat_data)) |
| 55 |
return NULL; |
| 56 |
|
| 57 |
/* NB: This is done as one big allocation, then assigning offptrs to |
| 58 |
* each sub-piece. (See _stp_pmap_new for more explanation) */ |
| 59 |
st = mem = _stp_shm_zalloc(total_size); |
| 60 |
if (st == NULL) |
| 61 |
return NULL; |
| 62 |
|
| 63 |
mem += stat_size; |
| 64 |
offptr_set(&st->oagg, mem); |
| 65 |
|
| 66 |
for_each_possible_cpu(i) { |
| 67 |
mem += stat_data_size; |
| 68 |
offptr_set(&st->osd[i], mem); |
| 69 |
} |
| 70 |
|
| 71 |
return st; |
| 72 |
} |
| 73 |
|
| 74 |
static void _stp_stat_free(Stat st) |
| 75 |
{ |
| 76 |
_stp_shm_free(st); |
| 77 |
} |
| 78 |
|
| 79 |
static inline stat_data* _stp_stat_get_agg(Stat st) |
| 80 |
{ |
| 81 |
return offptr_get(&st->oagg); |
| 82 |
} |
| 83 |
|
| 84 |
static inline stat_data* _stp_stat_per_cpu_ptr(Stat st, int cpu) |
| 85 |
{ |
| 86 |
return offptr_get(&st->osd[cpu]); |
| 87 |
} |
| 88 |
|
| 89 |
#endif /* _STAPDYN_STAT_RUNTIME_H_ */ |