0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _LINUX_FLEX_PROPORTIONS_H
0009 #define _LINUX_FLEX_PROPORTIONS_H
0010
0011 #include <linux/percpu_counter.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/seqlock.h>
0014 #include <linux/gfp.h>
0015
0016
0017
0018
0019
0020
0021
0022 #define FPROP_FRAC_SHIFT 10
0023 #define FPROP_FRAC_BASE (1UL << FPROP_FRAC_SHIFT)
0024
0025
0026
0027
0028 struct fprop_global {
0029
0030 struct percpu_counter events;
0031
0032 unsigned int period;
0033
0034 seqcount_t sequence;
0035 };
0036
0037 int fprop_global_init(struct fprop_global *p, gfp_t gfp);
0038 void fprop_global_destroy(struct fprop_global *p);
0039 bool fprop_new_period(struct fprop_global *p, int periods);
0040
0041
0042
0043
0044 struct fprop_local_single {
0045
0046 unsigned long events;
0047
0048 unsigned int period;
0049 raw_spinlock_t lock;
0050 };
0051
0052 #define INIT_FPROP_LOCAL_SINGLE(name) \
0053 { .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
0054 }
0055
0056 int fprop_local_init_single(struct fprop_local_single *pl);
0057 void fprop_local_destroy_single(struct fprop_local_single *pl);
0058 void __fprop_inc_single(struct fprop_global *p, struct fprop_local_single *pl);
0059 void fprop_fraction_single(struct fprop_global *p,
0060 struct fprop_local_single *pl, unsigned long *numerator,
0061 unsigned long *denominator);
0062
0063 static inline
0064 void fprop_inc_single(struct fprop_global *p, struct fprop_local_single *pl)
0065 {
0066 unsigned long flags;
0067
0068 local_irq_save(flags);
0069 __fprop_inc_single(p, pl);
0070 local_irq_restore(flags);
0071 }
0072
0073
0074
0075
0076 struct fprop_local_percpu {
0077
0078 struct percpu_counter events;
0079
0080 unsigned int period;
0081 raw_spinlock_t lock;
0082 };
0083
0084 int fprop_local_init_percpu(struct fprop_local_percpu *pl, gfp_t gfp);
0085 void fprop_local_destroy_percpu(struct fprop_local_percpu *pl);
0086 void __fprop_add_percpu(struct fprop_global *p, struct fprop_local_percpu *pl,
0087 long nr);
0088 void __fprop_add_percpu_max(struct fprop_global *p,
0089 struct fprop_local_percpu *pl, int max_frac, long nr);
0090 void fprop_fraction_percpu(struct fprop_global *p,
0091 struct fprop_local_percpu *pl, unsigned long *numerator,
0092 unsigned long *denominator);
0093
0094 static inline
0095 void fprop_inc_percpu(struct fprop_global *p, struct fprop_local_percpu *pl)
0096 {
0097 unsigned long flags;
0098
0099 local_irq_save(flags);
0100 __fprop_add_percpu(p, pl, 1);
0101 local_irq_restore(flags);
0102 }
0103
0104 #endif