Subversion Repositories Kolibri OS

Rev

Rev 5270 | Rev 6934 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5270 Rev 6082
Line 9... Line 9...
9
#include 
9
#include 
10
#include 
10
#include 
11
#include 
11
#include 
12
#include 
12
#include 
Line -... Line 13...
-
 
13
 
13
 
14
/* Don't assign or return these: may not be this big! */
Line 14... Line 15...
14
typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
15
typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
15
 
16
 
16
/**
17
/**
Line 20... Line 21...
20
 * You should only assume nr_cpu_ids bits of this mask are valid.  This is
21
 * You should only assume nr_cpu_ids bits of this mask are valid.  This is
21
 * a macro so it's const-correct.
22
 * a macro so it's const-correct.
22
 */
23
 */
23
#define cpumask_bits(maskp) ((maskp)->bits)
24
#define cpumask_bits(maskp) ((maskp)->bits)
Line -... Line 25...
-
 
25
 
-
 
26
/**
-
 
27
 * cpumask_pr_args - printf args to output a cpumask
-
 
28
 * @maskp: cpumask to be printed
-
 
29
 *
-
 
30
 * Can be used to provide arguments for '%*pb[l]' when printing a cpumask.
-
 
31
 */
-
 
32
#define cpumask_pr_args(maskp)		nr_cpu_ids, cpumask_bits(maskp)
24
 
33
 
25
#if NR_CPUS == 1
34
#if NR_CPUS == 1
26
#define nr_cpu_ids		1
35
#define nr_cpu_ids		1
27
#else
36
#else
28
extern int nr_cpu_ids;
37
extern int nr_cpu_ids;
Line 140... Line 149...
140
					   unsigned int cpu)
149
					   unsigned int cpu)
141
{
150
{
142
	return 1;
151
	return 1;
143
}
152
}
Line 144... Line 153...
144
 
153
 
145
static inline int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp)
154
static inline unsigned int cpumask_local_spread(unsigned int i, int node)
146
{
-
 
147
	set_bit(0, cpumask_bits(dstp));
-
 
148
 
155
{
149
	return 0;
156
	return 0;
Line 150... Line 157...
150
}
157
}
151
 
158
 
Line 197... Line 204...
197
	return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
204
	return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
198
}
205
}
Line 199... Line 206...
199
 
206
 
200
int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
207
int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
201
int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
208
int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
Line 202... Line 209...
202
int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
209
unsigned int cpumask_local_spread(unsigned int i, int node);
203
 
210
 
204
/**
211
/**
205
 * for_each_cpu - iterate over every cpu in a mask
212
 * for_each_cpu - iterate over every cpu in a mask
Line 279... Line 286...
279
 * cpumask_test_cpu - test for a cpu in a cpumask
286
 * cpumask_test_cpu - test for a cpu in a cpumask
280
 * @cpu: cpu number (< nr_cpu_ids)
287
 * @cpu: cpu number (< nr_cpu_ids)
281
 * @cpumask: the cpumask pointer
288
 * @cpumask: the cpumask pointer
282
 *
289
 *
283
 * Returns 1 if @cpu is set in @cpumask, else returns 0
290
 * Returns 1 if @cpu is set in @cpumask, else returns 0
284
 *
-
 
285
 * No static inline type checking - see Subtlety (1) above.
-
 
286
 */
291
 */
287
#define cpumask_test_cpu(cpu, cpumask) \
292
static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
-
 
293
{
288
	test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
294
	return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
-
 
295
}
Line 289... Line 296...
289
 
296
 
290
/**
297
/**
291
 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
298
 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
292
 * @cpu: cpu number (< nr_cpu_ids)
299
 * @cpu: cpu number (< nr_cpu_ids)
Line 537... Line 544...
537
 * @cpu: the cpu (<= nr_cpu_ids)
544
 * @cpu: the cpu (<= nr_cpu_ids)
538
 */
545
 */
539
#define cpumask_of(cpu) (get_cpu_mask(cpu))
546
#define cpumask_of(cpu) (get_cpu_mask(cpu))
Line 540... Line 547...
540
 
547
 
541
/**
-
 
542
 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
-
 
543
 * @buf: the buffer to sprintf into
-
 
544
 * @len: the length of the buffer
-
 
545
 * @srcp: the cpumask to print
-
 
546
 *
-
 
547
 * If len is zero, returns zero.  Otherwise returns the length of the
-
 
548
 * (nul-terminated) @buf string.
-
 
549
 */
-
 
550
static inline int cpumask_scnprintf(char *buf, int len,
-
 
551
				    const struct cpumask *srcp)
-
 
552
{
-
 
553
	return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
-
 
554
}
-
 
555
 
-
 
556
/**
548
/**
557
 * cpumask_parse_user - extract a cpumask from a user string
549
 * cpumask_parse_user - extract a cpumask from a user string
558
 * @buf: the buffer to extract from
550
 * @buf: the buffer to extract from
559
 * @len: the length of the buffer
551
 * @len: the length of the buffer
560
 * @dstp: the cpumask to set.
552
 * @dstp: the cpumask to set.
561
 *
553
 *
562
 * Returns -errno, or 0 for success.
554
 * Returns -errno, or 0 for success.
563
 */
555
 */
564
static inline int cpumask_parse_user(const char __user *buf, int len,
556
static inline int cpumask_parse_user(const char __user *buf, int len,
565
				     struct cpumask *dstp)
557
				     struct cpumask *dstp)
566
{
558
{
567
	return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
559
	return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpu_ids);
Line 568... Line 560...
568
}
560
}
569
 
561
 
570
/**
562
/**
Line 577... Line 569...
577
 */
569
 */
578
static inline int cpumask_parselist_user(const char __user *buf, int len,
570
static inline int cpumask_parselist_user(const char __user *buf, int len,
579
				     struct cpumask *dstp)
571
				     struct cpumask *dstp)
580
{
572
{
581
	return bitmap_parselist_user(buf, len, cpumask_bits(dstp),
573
	return bitmap_parselist_user(buf, len, cpumask_bits(dstp),
582
							nr_cpumask_bits);
-
 
583
}
-
 
584
 
-
 
585
/**
-
 
586
 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
-
 
587
 * @buf: the buffer to sprintf into
-
 
588
 * @len: the length of the buffer
-
 
589
 * @srcp: the cpumask to print
-
 
590
 *
-
 
591
 * If len is zero, returns zero.  Otherwise returns the length of the
-
 
592
 * (nul-terminated) @buf string.
-
 
593
 */
-
 
594
static inline int cpulist_scnprintf(char *buf, int len,
-
 
595
				    const struct cpumask *srcp)
-
 
596
{
-
 
597
	return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
-
 
598
				    nr_cpumask_bits);
574
				     nr_cpu_ids);
599
}
575
}
Line 600... Line 576...
600
 
576
 
601
/**
577
/**
602
 * cpumask_parse - extract a cpumask from from a string
578
 * cpumask_parse - extract a cpumask from from a string
Line 608... Line 584...
608
static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
584
static inline int cpumask_parse(const char *buf, struct cpumask *dstp)
609
{
585
{
610
	char *nl = strchr(buf, '\n');
586
	char *nl = strchr(buf, '\n');
611
	unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
587
	unsigned int len = nl ? (unsigned int)(nl - buf) : strlen(buf);
Line 612... Line 588...
612
 
588
 
613
	return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
589
	return bitmap_parse(buf, len, cpumask_bits(dstp), nr_cpu_ids);
Line 614... Line 590...
614
}
590
}
615
 
591
 
616
/**
592
/**
Line 620... Line 596...
620
 *
596
 *
621
 * Returns -errno, or 0 for success.
597
 * Returns -errno, or 0 for success.
622
 */
598
 */
623
static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
599
static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
624
{
600
{
625
	return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
601
	return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpu_ids);
626
}
602
}
Line 627... Line 603...
627
 
603
 
628
/**
604
/**
629
 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
605
 * cpumask_size - size to allocate for a 'struct cpumask' in bytes
630
 *
606
 *
631
 * This will eventually be a runtime variable, depending on nr_cpu_ids.
607
 * This will eventually be a runtime variable, depending on nr_cpu_ids.
632
 */
608
 */
633
static inline size_t cpumask_size(void)
609
static inline size_t cpumask_size(void)
634
{
-
 
635
	/* FIXME: Once all cpumask assignments are eliminated, this
-
 
636
	 * can be nr_cpumask_bits */
610
{
637
	return BITS_TO_LONGS(NR_CPUS) * sizeof(long);
611
	return BITS_TO_LONGS(nr_cpumask_bits) * sizeof(long);
Line 638... Line 612...
638
}
612
}
639
 
613
 
640
/*
614
/*
Line 789... Line 763...
789
#define cpu_is_offline(cpu)	unlikely(!cpu_online(cpu))
763
#define cpu_is_offline(cpu)	unlikely(!cpu_online(cpu))
Line 790... Line 764...
790
 
764
 
791
#if NR_CPUS <= BITS_PER_LONG
765
#if NR_CPUS <= BITS_PER_LONG
792
#define CPU_BITS_ALL						\
766
#define CPU_BITS_ALL						\
793
{								\
767
{								\
794
	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD	\
768
	[BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS)	\
Line 795... Line 769...
795
}
769
}
Line 796... Line 770...
796
 
770
 
797
#else /* NR_CPUS > BITS_PER_LONG */
771
#else /* NR_CPUS > BITS_PER_LONG */
798
 
772
 
799
#define CPU_BITS_ALL						\
773
#define CPU_BITS_ALL						\
800
{								\
774
{								\
801
	[0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL,		\
775
	[0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL,		\
Line 802... Line 776...
802
	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD		\
776
	[BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS)	\
803
}
777
}
Line 815... Line 789...
815
 */
789
 */
816
static inline ssize_t
790
static inline ssize_t
817
cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
791
cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
818
{
792
{
819
	return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
793
	return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
820
				      nr_cpumask_bits);
794
				      nr_cpu_ids);
821
}
795
}
Line 822... Line -...
822
 
-
 
823
/*
-
 
824
 *
-
 
825
 * From here down, all obsolete.  Use cpumask_ variants!
-
 
826
 *
-
 
827
 */
-
 
828
#ifndef CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
-
 
829
#define cpumask_of_cpu(cpu) (*get_cpu_mask(cpu))
-
 
830
 
-
 
831
#define CPU_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(NR_CPUS)
-
 
832
 
796
 
833
#if NR_CPUS <= BITS_PER_LONG
-
 
834
 
797
#if NR_CPUS <= BITS_PER_LONG
835
#define CPU_MASK_ALL							\
798
#define CPU_MASK_ALL							\
836
(cpumask_t) { {								\
799
(cpumask_t) { {								\
837
	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD			\
800
	[BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS)	\
838
} }
-
 
839
 
801
} }
840
#else
-
 
841
 
802
#else
842
#define CPU_MASK_ALL							\
803
#define CPU_MASK_ALL							\
843
(cpumask_t) { {								\
804
(cpumask_t) { {								\
844
	[0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL,			\
805
	[0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL,			\
845
	[BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD			\
806
	[BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS)	\
846
} }
-
 
847
 
807
} }
Line 848... Line 808...
848
#endif
808
#endif /* NR_CPUS > BITS_PER_LONG */
849
 
809
 
850
#define CPU_MASK_NONE							\
810
#define CPU_MASK_NONE							\
851
(cpumask_t) { {								\
811
(cpumask_t) { {								\
Line 855... Line 815...
855
#define CPU_MASK_CPU0							\
815
#define CPU_MASK_CPU0							\
856
(cpumask_t) { {								\
816
(cpumask_t) { {								\
857
	[0] =  1UL							\
817
	[0] =  1UL							\
858
} }
818
} }
Line 859... Line -...
859
 
-
 
860
#if NR_CPUS == 1
-
 
861
#define first_cpu(src)		({ (void)(src); 0; })
-
 
862
#define next_cpu(n, src)	({ (void)(src); 1; })
-
 
863
#define any_online_cpu(mask)	0
-
 
864
#define for_each_cpu_mask(cpu, mask)	\
-
 
865
	for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
-
 
866
#else /* NR_CPUS > 1 */
-
 
867
int __first_cpu(const cpumask_t *srcp);
-
 
868
int __next_cpu(int n, const cpumask_t *srcp);
-
 
869
 
-
 
870
#define first_cpu(src)		__first_cpu(&(src))
-
 
871
#define next_cpu(n, src)	__next_cpu((n), &(src))
-
 
872
#define any_online_cpu(mask) cpumask_any_and(&mask, cpu_online_mask)
-
 
873
#define for_each_cpu_mask(cpu, mask)			\
-
 
874
	for ((cpu) = -1;				\
-
 
875
		(cpu) = next_cpu((cpu), (mask)),	\
-
 
876
		(cpu) < NR_CPUS; )
-
 
877
#endif /* SMP */
-
 
878
 
-
 
879
#if NR_CPUS <= 64
-
 
880
 
-
 
881
#define for_each_cpu_mask_nr(cpu, mask)	for_each_cpu_mask(cpu, mask)
-
 
882
 
-
 
883
#else /* NR_CPUS > 64 */
-
 
884
 
-
 
885
int __next_cpu_nr(int n, const cpumask_t *srcp);
-
 
886
#define for_each_cpu_mask_nr(cpu, mask)			\
-
 
887
	for ((cpu) = -1;				\
-
 
888
		(cpu) = __next_cpu_nr((cpu), &(mask)),	\
-
 
889
		(cpu) < nr_cpu_ids; )
-
 
890
 
-
 
891
#endif /* NR_CPUS > 64 */
-
 
892
 
-
 
893
#define cpus_addr(src) ((src).bits)
-
 
894
 
-
 
895
#define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
-
 
896
static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
-
 
897
{
-
 
898
	set_bit(cpu, dstp->bits);
-
 
899
}
-
 
900
 
-
 
901
#define cpu_clear(cpu, dst) __cpu_clear((cpu), &(dst))
-
 
902
static inline void __cpu_clear(int cpu, volatile cpumask_t *dstp)
-
 
903
{
-
 
904
	clear_bit(cpu, dstp->bits);
-
 
905
}
-
 
906
 
-
 
907
#define cpus_setall(dst) __cpus_setall(&(dst), NR_CPUS)
-
 
908
static inline void __cpus_setall(cpumask_t *dstp, int nbits)
-
 
909
{
-
 
910
	bitmap_fill(dstp->bits, nbits);
-
 
911
}
-
 
912
 
-
 
913
#define cpus_clear(dst) __cpus_clear(&(dst), NR_CPUS)
-
 
914
static inline void __cpus_clear(cpumask_t *dstp, int nbits)
-
 
915
{
-
 
916
	bitmap_zero(dstp->bits, nbits);
-
 
917
}
-
 
918
 
-
 
919
/* No static inline type checking - see Subtlety (1) above. */
-
 
920
#define cpu_isset(cpu, cpumask) test_bit((cpu), (cpumask).bits)
-
 
921
 
-
 
922
#define cpu_test_and_set(cpu, cpumask) __cpu_test_and_set((cpu), &(cpumask))
-
 
923
static inline int __cpu_test_and_set(int cpu, cpumask_t *addr)
-
 
924
{
-
 
925
	return test_and_set_bit(cpu, addr->bits);
-
 
926
}
-
 
927
 
-
 
928
#define cpus_and(dst, src1, src2) __cpus_and(&(dst), &(src1), &(src2), NR_CPUS)
-
 
929
static inline int __cpus_and(cpumask_t *dstp, const cpumask_t *src1p,
-
 
930
					const cpumask_t *src2p, int nbits)
-
 
931
{
-
 
932
	return bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
-
 
933
}
-
 
934
 
-
 
935
#define cpus_or(dst, src1, src2) __cpus_or(&(dst), &(src1), &(src2), NR_CPUS)
-
 
936
static inline void __cpus_or(cpumask_t *dstp, const cpumask_t *src1p,
-
 
937
					const cpumask_t *src2p, int nbits)
-
 
938
{
-
 
939
	bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
-
 
940
}
-
 
941
 
-
 
942
#define cpus_xor(dst, src1, src2) __cpus_xor(&(dst), &(src1), &(src2), NR_CPUS)
-
 
943
static inline void __cpus_xor(cpumask_t *dstp, const cpumask_t *src1p,
-
 
944
					const cpumask_t *src2p, int nbits)
-
 
945
{
-
 
946
	bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
-
 
947
}
-
 
948
 
-
 
949
#define cpus_andnot(dst, src1, src2) \
-
 
950
				__cpus_andnot(&(dst), &(src1), &(src2), NR_CPUS)
-
 
951
static inline int __cpus_andnot(cpumask_t *dstp, const cpumask_t *src1p,
-
 
952
					const cpumask_t *src2p, int nbits)
-
 
953
{
-
 
954
	return bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
-
 
955
}
-
 
956
 
-
 
957
#define cpus_equal(src1, src2) __cpus_equal(&(src1), &(src2), NR_CPUS)
-
 
958
static inline int __cpus_equal(const cpumask_t *src1p,
-
 
959
					const cpumask_t *src2p, int nbits)
-
 
960
{
-
 
961
	return bitmap_equal(src1p->bits, src2p->bits, nbits);
-
 
962
}
-
 
963
 
-
 
964
#define cpus_intersects(src1, src2) __cpus_intersects(&(src1), &(src2), NR_CPUS)
-
 
965
static inline int __cpus_intersects(const cpumask_t *src1p,
-
 
966
					const cpumask_t *src2p, int nbits)
-
 
967
{
-
 
968
	return bitmap_intersects(src1p->bits, src2p->bits, nbits);
-
 
969
}
-
 
970
 
-
 
971
#define cpus_subset(src1, src2) __cpus_subset(&(src1), &(src2), NR_CPUS)
-
 
972
static inline int __cpus_subset(const cpumask_t *src1p,
-
 
973
					const cpumask_t *src2p, int nbits)
-
 
974
{
-
 
975
	return bitmap_subset(src1p->bits, src2p->bits, nbits);
-
 
976
}
-
 
977
 
-
 
978
#define cpus_empty(src) __cpus_empty(&(src), NR_CPUS)
-
 
979
static inline int __cpus_empty(const cpumask_t *srcp, int nbits)
-
 
980
{
-
 
981
	return bitmap_empty(srcp->bits, nbits);
-
 
982
}
-
 
983
 
-
 
984
#define cpus_weight(cpumask) __cpus_weight(&(cpumask), NR_CPUS)
-
 
985
static inline int __cpus_weight(const cpumask_t *srcp, int nbits)
-
 
986
{
-
 
987
	return bitmap_weight(srcp->bits, nbits);
-
 
988
}
-
 
989
 
-
 
990
#define cpus_shift_left(dst, src, n) \
-
 
991
			__cpus_shift_left(&(dst), &(src), (n), NR_CPUS)
-
 
992
static inline void __cpus_shift_left(cpumask_t *dstp,
-
 
993
					const cpumask_t *srcp, int n, int nbits)
-
 
994
{
-
 
995
	bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
-
 
996
}
-
 
997
#endif /* !CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS */
-
 
998
 
819