aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h121
1 files changed, 30 insertions, 91 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e8343422240a..645231c373c8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -1,6 +1,8 @@
1#ifndef _LINUX_KERNEL_H 1#ifndef _LINUX_KERNEL_H
2#define _LINUX_KERNEL_H 2#define _LINUX_KERNEL_H
3 3
4#include <linux/sysinfo.h>
5
4/* 6/*
5 * 'kernel.h' contains some often-used function prototypes etc 7 * 'kernel.h' contains some often-used function prototypes etc
6 */ 8 */
@@ -20,7 +22,6 @@
20#include <linux/printk.h> 22#include <linux/printk.h>
21#include <linux/dynamic_debug.h> 23#include <linux/dynamic_debug.h>
22#include <asm/byteorder.h> 24#include <asm/byteorder.h>
23#include <asm/bug.h>
24 25
25#define USHRT_MAX ((u16)(~0U)) 26#define USHRT_MAX ((u16)(~0U))
26#define SHRT_MAX ((s16)(USHRT_MAX>>1)) 27#define SHRT_MAX ((s16)(USHRT_MAX>>1))
@@ -85,6 +86,19 @@
85} \ 86} \
86) 87)
87 88
89/*
90 * Multiplies an integer by a fraction, while avoiding unnecessary
91 * overflow or loss of precision.
92 */
93#define mult_frac(x, numer, denom)( \
94{ \
95 typeof(x) quot = (x) / (denom); \
96 typeof(x) rem = (x) % (denom); \
97 (quot * (numer)) + ((rem * (numer)) / (denom)); \
98} \
99)
100
101
88#define _RET_IP_ (unsigned long)__builtin_return_address(0) 102#define _RET_IP_ (unsigned long)__builtin_return_address(0)
89#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) 103#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
90 104
@@ -299,6 +313,8 @@ extern long long simple_strtoll(const char *,char **,unsigned int);
299#define strict_strtoull kstrtoull 313#define strict_strtoull kstrtoull
300#define strict_strtoll kstrtoll 314#define strict_strtoll kstrtoll
301 315
316extern int num_to_str(char *buf, int size, unsigned long long num);
317
302/* lib/printf utilities */ 318/* lib/printf utilities */
303 319
304extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); 320extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
@@ -315,10 +331,10 @@ extern __printf(2, 3)
315char *kasprintf(gfp_t gfp, const char *fmt, ...); 331char *kasprintf(gfp_t gfp, const char *fmt, ...);
316extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); 332extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
317 333
318extern int sscanf(const char *, const char *, ...) 334extern __scanf(2, 3)
319 __attribute__ ((format (scanf, 2, 3))); 335int sscanf(const char *, const char *, ...);
320extern int vsscanf(const char *, const char *, va_list) 336extern __scanf(2, 0)
321 __attribute__ ((format (scanf, 2, 0))); 337int vsscanf(const char *, const char *, va_list);
322 338
323extern int get_option(char **str, int *pint); 339extern int get_option(char **str, int *pint);
324extern char *get_options(const char *str, int nints, int *ints); 340extern char *get_options(const char *str, int nints, int *ints);
@@ -414,16 +430,10 @@ extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
414 * Most likely, you want to use tracing_on/tracing_off. 430 * Most likely, you want to use tracing_on/tracing_off.
415 */ 431 */
416#ifdef CONFIG_RING_BUFFER 432#ifdef CONFIG_RING_BUFFER
417void tracing_on(void);
418void tracing_off(void);
419/* trace_off_permanent stops recording with no way to bring it back */ 433/* trace_off_permanent stops recording with no way to bring it back */
420void tracing_off_permanent(void); 434void tracing_off_permanent(void);
421int tracing_is_on(void);
422#else 435#else
423static inline void tracing_on(void) { }
424static inline void tracing_off(void) { }
425static inline void tracing_off_permanent(void) { } 436static inline void tracing_off_permanent(void) { }
426static inline int tracing_is_on(void) { return 0; }
427#endif 437#endif
428 438
429enum ftrace_dump_mode { 439enum ftrace_dump_mode {
@@ -433,6 +443,10 @@ enum ftrace_dump_mode {
433}; 443};
434 444
435#ifdef CONFIG_TRACING 445#ifdef CONFIG_TRACING
446void tracing_on(void);
447void tracing_off(void);
448int tracing_is_on(void);
449
436extern void tracing_start(void); 450extern void tracing_start(void);
437extern void tracing_stop(void); 451extern void tracing_stop(void);
438extern void ftrace_off_permanent(void); 452extern void ftrace_off_permanent(void);
@@ -517,6 +531,11 @@ static inline void tracing_start(void) { }
517static inline void tracing_stop(void) { } 531static inline void tracing_stop(void) { }
518static inline void ftrace_off_permanent(void) { } 532static inline void ftrace_off_permanent(void) { }
519static inline void trace_dump_stack(void) { } 533static inline void trace_dump_stack(void) { }
534
535static inline void tracing_on(void) { }
536static inline void tracing_off(void) { }
537static inline int tracing_is_on(void) { return 0; }
538
520static inline int 539static inline int
521trace_printk(const char *fmt, ...) 540trace_printk(const char *fmt, ...)
522{ 541{
@@ -662,67 +681,6 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
662 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 681 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
663 (type *)( (char *)__mptr - offsetof(type,member) );}) 682 (type *)( (char *)__mptr - offsetof(type,member) );})
664 683
665#ifdef __CHECKER__
666#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
667#define BUILD_BUG_ON_ZERO(e) (0)
668#define BUILD_BUG_ON_NULL(e) ((void*)0)
669#define BUILD_BUG_ON(condition)
670#define BUILD_BUG() (0)
671#else /* __CHECKER__ */
672
673/* Force a compilation error if a constant expression is not a power of 2 */
674#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
675 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
676
677/* Force a compilation error if condition is true, but also produce a
678 result (of value 0 and type size_t), so the expression can be used
679 e.g. in a structure initializer (or where-ever else comma expressions
680 aren't permitted). */
681#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
682#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
683
684/**
685 * BUILD_BUG_ON - break compile if a condition is true.
686 * @condition: the condition which the compiler should know is false.
687 *
688 * If you have some code which relies on certain constants being equal, or
689 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
690 * detect if someone changes it.
691 *
692 * The implementation uses gcc's reluctance to create a negative array, but
693 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
694 * to inline functions). So as a fallback we use the optimizer; if it can't
695 * prove the condition is false, it will cause a link error on the undefined
696 * "__build_bug_on_failed". This error message can be harder to track down
697 * though, hence the two different methods.
698 */
699#ifndef __OPTIMIZE__
700#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
701#else
702extern int __build_bug_on_failed;
703#define BUILD_BUG_ON(condition) \
704 do { \
705 ((void)sizeof(char[1 - 2*!!(condition)])); \
706 if (condition) __build_bug_on_failed = 1; \
707 } while(0)
708#endif
709
710/**
711 * BUILD_BUG - break compile if used.
712 *
713 * If you have some code that you expect the compiler to eliminate at
714 * build time, you should use BUILD_BUG to detect if it is
715 * unexpectedly used.
716 */
717#define BUILD_BUG() \
718 do { \
719 extern void __build_bug_failed(void) \
720 __linktime_error("BUILD_BUG failed"); \
721 __build_bug_failed(); \
722 } while (0)
723
724#endif /* __CHECKER__ */
725
726/* Trap pasters of __FUNCTION__ at compile-time */ 684/* Trap pasters of __FUNCTION__ at compile-time */
727#define __FUNCTION__ (__func__) 685#define __FUNCTION__ (__func__)
728 686
@@ -745,27 +703,8 @@ extern int __build_bug_on_failed;
745# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD 703# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
746#endif 704#endif
747 705
748struct sysinfo;
749extern int do_sysinfo(struct sysinfo *info); 706extern int do_sysinfo(struct sysinfo *info);
750 707
751#endif /* __KERNEL__ */ 708#endif /* __KERNEL__ */
752 709
753#define SI_LOAD_SHIFT 16
754struct sysinfo {
755 long uptime; /* Seconds since boot */
756 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
757 unsigned long totalram; /* Total usable main memory size */
758 unsigned long freeram; /* Available memory size */
759 unsigned long sharedram; /* Amount of shared memory */
760 unsigned long bufferram; /* Memory used by buffers */
761 unsigned long totalswap; /* Total swap space size */
762 unsigned long freeswap; /* swap space still available */
763 unsigned short procs; /* Number of current processes */
764 unsigned short pad; /* explicit padding for m68k */
765 unsigned long totalhigh; /* Total high memory size */
766 unsigned long freehigh; /* Available high memory size */
767 unsigned int mem_unit; /* Memory unit size in bytes */
768 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
769};
770
771#endif 710#endif