include/nucleus/stat.h

00001 /*
00002  * Copyright (C) 2006 Jan Kiszka <jan.kiszka@web.de>.
00003  * Copyright (C) 2006 Dmitry Adamushko <dmitry.adamushko@gmail.com>.
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 #ifdef CONFIG_XENO_OPT_STATS
00025 
00026 #include <nucleus/types.h>
00027 
00028 typedef struct xnstat_runtime {
00029 
00030         xnticks_t start;   /* Start of execution time accumulation */
00031 
00032         xnticks_t total; /* Accumulated execution time */
00033 
00034 } xnstat_runtime_t;
00035 
00036 /* Return current date which can be passed to other xnstat services for
00037    immediate or lazy accounting. */
00038 #define xnstat_runtime_now() xnarch_get_cpu_tsc()
00039 
00040 /* Accumulate runtime of the current account until the given date. */
00041 #define xnstat_runtime_update(sched, start) \
00042 do { \
00043         (sched)->current_account->total += \
00044                 start - (sched)->last_account_switch; \
00045         (sched)->last_account_switch = start; \
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_runtime_set_current(sched, new_account) \
00053 ({ \
00054         xnstat_runtime_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_runtime_get_current(sched) ((sched)->current_account)
00061 
00062 /* Finalize an account (no need to accumulate the runtime, just mark the
00063    switch date and set the new account). */
00064 #define xnstat_runtime_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 /* Reset statistics from inside the accounted entity (e.g. after CPU
00071    migration). */
00072 #define xnstat_runtime_reset_stats(stat) \
00073 do { \
00074         (stat)->total = 0; \
00075         (stat)->start = xnarch_get_cpu_tsc(); \
00076 } while (0)
00077 
00078 
00079 typedef struct xnstat_counter {
00080         int counter;
00081 } xnstat_counter_t;
00082 
00083 static inline int xnstat_counter_inc(xnstat_counter_t *c) {
00084         return c->counter++;
00085 }
00086 
00087 static inline int xnstat_counter_get(xnstat_counter_t *c) {
00088         return c->counter;
00089 }
00090 
00091 #else /* !CONFIG_XENO_OPT_STATS */
00092 typedef struct xnstat_runtime {
00093 } xnstat_runtime_t;
00094 
00095 #define xnstat_runtime_now()                                 0
00096 #define xnstat_runtime_update(sched, start)                  do { } while (0)
00097 #define xnstat_runtime_set_current(sched, new_account)       ({ NULL; })
00098 #define xnstat_runtime_get_current(sched)                    ({ NULL; })
00099 #define xnstat_runtime_finalize(sched, new_account)          do { } while (0)
00100 #define xnstat_runtime_reset_stats(account)                  do { } while (0)
00101 
00102 typedef struct xnstat_counter {
00103 } xnstat_counter_t;
00104 
00105 static inline int xnstat_counter_inc(xnstat_counter_t *c) { return 0; }
00106 static inline int xnstat_counter_get(xnstat_counter_t *c) { return 0; }
00107 #endif /* CONFIG_XENO_OPT_STATS */
00108 
00109 /* Account the runtime of the current account until now, switch to
00110    new_account, and return the previous one. */
00111 #define xnstat_runtime_switch(sched, new_account) \
00112 ({ \
00113         xnstat_runtime_update(sched, xnstat_runtime_now()); \
00114         xnstat_runtime_set_current(sched, new_account); \
00115 })
00116 
00117 /* Account the runtime of the current account until given start time, switch
00118    to new_account, and return the previous one. */
00119 #define xnstat_runtime_lazy_switch(sched, new_account, start) \
00120 ({ \
00121         xnstat_runtime_update(sched, start); \
00122         xnstat_runtime_set_current(sched, new_account); \
00123 })
00124 
00125 #endif /* !_XENO_NUCLEUS_STAT_H */

Generated on Sun Dec 9 10:37:17 2007 for Xenomai API by  doxygen 1.5.3