Debian Codegraph @

runtime/linux/stat_runtime.h

raw
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 _LINUX_STAT_RUNTIME_H_
12 #define _LINUX_STAT_RUNTIME_H_
13
14 #define STAT_LOCK(sd) do {} while (0)
15 #define STAT_UNLOCK(sd) do {} while (0)
16 /* get/put_cpu wrappers. Unnecessary if caller is already atomic. */
17 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT_RT)
18 #define STAT_GET_CPU() raw_smp_processor_id()
19 #else
20 #define STAT_GET_CPU() smp_processor_id()
21 #endif
22 #define STAT_PUT_CPU() do {} while (0)
23
24 /** Stat struct. Maps do not need this */
25 typedef struct _Stat {
26 struct _Hist hist;
27
28 /* aggregated data */
29 stat_data *agg;
30
31 /* The stat data is per-cpu data. */
32 stat_data __percpu *sd;
33 } *Stat;
34
35 static Stat _stp_stat_alloc(size_t stat_data_size)
36 {
37 Stat st;
38
39 if (stat_data_size < sizeof(stat_data))
40 return NULL;
41
42 /* Called from module_init, so user context, may sleep alloc. */
43 st = _stp_kmalloc_gfp (sizeof(struct _Stat), STP_ALLOC_SLEEP_FLAGS);
44 if (st == NULL)
45 return NULL;
46
47 st->agg = _stp_kzalloc_gfp (stat_data_size, STP_ALLOC_SLEEP_FLAGS);
48 if (st->agg == NULL) {
49 _stp_kfree (st);
50 return NULL;
51 }
52
53 st->sd = _stp_alloc_percpu (stat_data_size);
54 if (st->sd == NULL) {
55 _stp_kfree (st->agg);
56 _stp_kfree (st);
57 return NULL;
58 }
59
60 return st;
61 }
62
63 static void _stp_stat_free(Stat st)
64 {
65 if (st) {
66 _stp_free_percpu (st->sd);
67 _stp_kfree (st->agg);
68 _stp_kfree (st);
69 }
70 }
71
72 #define _stp_stat_get_agg(stat) ((stat)->agg)
73 #define _stp_stat_per_cpu_ptr(stat, cpu) per_cpu_ptr((stat)->sd, (cpu))
74
75 #endif /* _LINUX_STAT_RUNTIME_H_ */