Xenomai API
2.5.6.1
|
00001 /* 00002 * Copyright (C) 2006 Jan Kiszka <[email protected]>. 00003 * Copyright (C) 2006 Dmitry Adamushko <[email protected]>. 00004 * 00005 * Xenomai is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published 00007 * by the Free Software Foundation; either version 2 of the License, 00008 * or (at your option) any later version. 00009 * 00010 * Xenomai is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with Xenomai; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00018 * 02111-1307, USA. 00019 */ 00020 00021 #ifndef _XENO_NUCLEUS_STAT_H 00022 #define _XENO_NUCLEUS_STAT_H 00023 00024 #include <nucleus/types.h> /* This pulls in linux/config.h with legacy kernels. */ 00025 00026 #ifdef CONFIG_XENO_OPT_STATS 00027 00028 typedef struct xnstat_exectime { 00029 00030 xnticks_t start; /* Start of execution time accumulation */ 00031 00032 xnticks_t total; /* Accumulated execution time */ 00033 00034 } xnstat_exectime_t; 00035 00036 /* Return current date which can be passed to other xnstat services for 00037 immediate or lazy accounting. */ 00038 #define xnstat_exectime_now() xnarch_get_cpu_tsc() 00039 00040 /* Accumulate exectime of the current account until the given date. */ 00041 #define xnstat_exectime_update(sched, date) \ 00042 do { \ 00043 (sched)->current_account->total += \ 00044 date - (sched)->last_account_switch; \ 00045 (sched)->last_account_switch = date; \ 00046 /* All changes must be committed before changing the current_account \ 00047 reference in sched (required for xnintr_sync_stat_references) */ \ 00048 xnarch_memory_barrier(); \ 00049 } while (0) 00050 00051 /* Update the current account reference, returning the previous one. */ 00052 #define xnstat_exectime_set_current(sched, new_account) \ 00053 ({ \ 00054 xnstat_exectime_t *__prev; \ 00055 __prev = xnarch_atomic_xchg(&(sched)->current_account, (new_account)); \ 00056 __prev; \ 00057 }) 00058 00059 /* Return the currently active accounting entity. */ 00060 #define xnstat_exectime_get_current(sched) ((sched)->current_account) 00061 00062 /* Finalize an account (no need to accumulate the exectime, just mark the 00063 switch date and set the new account). */ 00064 #define xnstat_exectime_finalize(sched, new_account) \ 00065 do { \ 00066 (sched)->last_account_switch = xnarch_get_cpu_tsc(); \ 00067 (sched)->current_account = (new_account); \ 00068 } while (0) 00069 00070 /* Obtain content of xnstat_exectime_t */ 00071 #define xnstat_exectime_get_start(account) ((account)->start) 00072 #define xnstat_exectime_get_total(account) ((account)->total) 00073 00074 /* Obtain last account switch date of considered sched */ 00075 #define xnstat_exectime_get_last_switch(sched) ((sched)->last_account_switch) 00076 00077 /* Reset statistics from inside the accounted entity (e.g. after CPU 00078 migration). */ 00079 #define xnstat_exectime_reset_stats(stat) \ 00080 do { \ 00081 (stat)->total = 0; \ 00082 (stat)->start = xnarch_get_cpu_tsc(); \ 00083 } while (0) 00084 00085 00086 typedef struct xnstat_counter { 00087 unsigned long counter; 00088 } xnstat_counter_t; 00089 00090 static inline unsigned long xnstat_counter_inc(xnstat_counter_t *c) 00091 { 00092 return c->counter++; 00093 } 00094 00095 static inline unsigned long xnstat_counter_get(xnstat_counter_t *c) 00096 { 00097 return c->counter; 00098 } 00099 00100 static inline void xnstat_counter_set(xnstat_counter_t *c, unsigned long value) 00101 { 00102 c->counter = value; 00103 } 00104 00105 #else /* !CONFIG_XENO_OPT_STATS */ 00106 typedef struct xnstat_exectime { 00107 #ifdef __XENO_SIM__ 00108 int dummy; 00109 #endif /* __XENO_SIM__ */ 00110 } xnstat_exectime_t; 00111 00112 #define xnstat_exectime_now() ({ 0; }) 00113 #define xnstat_exectime_update(sched, date) do { } while (0) 00114 #define xnstat_exectime_set_current(sched, new_account) ({ (void)sched; NULL; }) 00115 #define xnstat_exectime_get_current(sched) ({ (void)sched; NULL; }) 00116 #define xnstat_exectime_finalize(sched, new_account) do { } while (0) 00117 #define xnstat_exectime_get_start(account) ({ 0; }) 00118 #define xnstat_exectime_get_total(account) ({ 0; }) 00119 #define xnstat_exectime_get_last_switch(sched) ({ 0; }) 00120 #define xnstat_exectime_reset_stats(account) do { } while (0) 00121 00122 typedef struct xnstat_counter { 00123 #ifdef __XENO_SIM__ 00124 int dummy; 00125 #endif /* __XENO_SIM__ */ 00126 } xnstat_counter_t; 00127 00128 #define xnstat_counter_inc(c) ({ do { } while(0); 0; }) 00129 #define xnstat_counter_get(c) ({ 0; }) 00130 #define xnstat_counter_set(c, value) do { } while (0) 00131 #endif /* CONFIG_XENO_OPT_STATS */ 00132 00133 /* Account the exectime of the current account until now, switch to 00134 new_account, and return the previous one. */ 00135 #define xnstat_exectime_switch(sched, new_account) \ 00136 ({ \ 00137 xnstat_exectime_update(sched, xnstat_exectime_now()); \ 00138 xnstat_exectime_set_current(sched, new_account); \ 00139 }) 00140 00141 /* Account the exectime of the current account until given start time, switch 00142 to new_account, and return the previous one. */ 00143 #define xnstat_exectime_lazy_switch(sched, new_account, date) \ 00144 ({ \ 00145 xnstat_exectime_update(sched, date); \ 00146 xnstat_exectime_set_current(sched, new_account); \ 00147 }) 00148 00149 #endif /* !_XENO_NUCLEUS_STAT_H */