* [PATCH 0/6] add generic round_up_pow2() macro
@ 2005-04-08 0:44 Nick Wilson
2005-04-08 0:48 ` [PATCH 1/6] include/linux/kernel.h: use " Nick Wilson
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:44 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
Randy.Dunlap wrote:
> >+#define ALIGN_DATA_SIZE(size) ((size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
>
> ISTM that we need a generic round_up() function or macro in kernel.h.
>
> a.out.h, reiserfs_fs.h, and ufs_fs.h all have their own round-up
> macros.
I've found many more places in the kernel that use their own functions for
doing this. These patches are the beginning of an attempt to clean these
up.
The first patch adds a generic round_up_pow2() macro to kernel.h. The
remaining patches modify a few files to make use of the new macro.
Comments welcome.
Thanks,
Nick
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/6] include/linux/kernel.h: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
@ 2005-04-08 0:48 ` Nick Wilson
2005-04-08 0:49 ` [PATCH 2/6] " Nick Wilson
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:48 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Add a generic macro to kernel.h to round up to the next multiple of n.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
kernel.h | 5 +++++
1 files changed, 5 insertions(+)
Index: linux/include/linux/kernel.h
===================================================================
--- linux.orig/include/linux/kernel.h 2005-04-07 15:13:56.000000000 -0700
+++ linux/include/linux/kernel.h 2005-04-07 15:47:15.000000000 -0700
@@ -246,6 +246,11 @@ extern void dump_stack(void);
#define max_t(type,x,y) \
({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+/*
+ * Round x up to the next multiple of n.
+ * n must be a power of 2.
+ */
+#define round_up_pow2(x,n) (((x) + (n) - 1) & ~((n) - 1))
/**
* container_of - cast a member of a structure out to the containing structure
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/6] include/linux/kernel.h: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
2005-04-08 0:48 ` [PATCH 1/6] include/linux/kernel.h: use " Nick Wilson
@ 2005-04-08 0:49 ` Nick Wilson
2005-04-08 0:50 ` [PATCH 3/6] include/linux/a.out.h: " Nick Wilson
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:49 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Use the generic round_up_pow2() instead of a custom rounding method.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
kernel.h | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: linux/include/linux/kernel.h
===================================================================
--- linux.orig/include/linux/kernel.h 2005-04-07 15:44:05.000000000 -0700
+++ linux/include/linux/kernel.h 2005-04-07 15:44:53.000000000 -0700
@@ -28,7 +28,7 @@ extern const char linux_banner[];
#define STACK_MAGIC 0xdeadbeef
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
+#define ALIGN round_up_pow2
#define KERN_EMERG "<0>" /* system is unusable */
#define KERN_ALERT "<1>" /* action must be taken immediately */
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/6] include/linux/a.out.h: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
2005-04-08 0:48 ` [PATCH 1/6] include/linux/kernel.h: use " Nick Wilson
2005-04-08 0:49 ` [PATCH 2/6] " Nick Wilson
@ 2005-04-08 0:50 ` Nick Wilson
2005-04-08 0:50 ` [PATCH 0/6] add " Andrew Morton
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:50 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Use the generic round_up_pow2() instead of a custom rounding method.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
a.out.h | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: linux/include/linux/a.out.h
===================================================================
--- linux.orig/include/linux/a.out.h 2005-04-07 15:37:22.000000000 -0700
+++ linux/include/linux/a.out.h 2005-04-07 15:45:34.000000000 -0700
@@ -138,7 +138,7 @@ enum machine_type {
#endif
#endif
-#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+#define _N_SEGMENT_ROUND(x) round_up_pow2(x, SEGMENT_SIZE)
#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] add generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
` (2 preceding siblings ...)
2005-04-08 0:50 ` [PATCH 3/6] include/linux/a.out.h: " Nick Wilson
@ 2005-04-08 0:50 ` Andrew Morton
2005-04-08 9:57 ` P
2005-04-08 18:50 ` [PATCH] Use ALIGN to remove duplicate code Nick Wilson
2005-04-08 0:50 ` [PATCH 4/6] kernel/resource.c: use generic round_up_pow2() macro Nick Wilson
` (2 subsequent siblings)
6 siblings, 2 replies; 11+ messages in thread
From: Andrew Morton @ 2005-04-08 0:50 UTC (permalink / raw)
To: Nick Wilson; +Cc: linux-kernel, rddunlap
Nick Wilson <njw@osdl.org> wrote:
>
> The first patch adds a generic round_up_pow2() macro to kernel.h. The
> remaining patches modify a few files to make use of the new macro.
We already have ALIGN() and roundup_pow_of_two().
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/6] kernel/resource.c: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
` (3 preceding siblings ...)
2005-04-08 0:50 ` [PATCH 0/6] add " Andrew Morton
@ 2005-04-08 0:50 ` Nick Wilson
2005-04-08 0:51 ` [PATCH 5/6] lib/bitmap.c: " Nick Wilson
2005-04-08 0:52 ` [PATCH 6/6] mm/bootmem.c: " Nick Wilson
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:50 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Use the generic round_up_pow2() instead of a custom rounding method.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
resource.c | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: linux/kernel/resource.c
===================================================================
--- linux.orig/kernel/resource.c 2005-04-07 15:13:56.000000000 -0700
+++ linux/kernel/resource.c 2005-04-07 15:45:57.000000000 -0700
@@ -263,7 +263,7 @@ static int find_resource(struct resource
new->start = min;
if (new->end > max)
new->end = max;
- new->start = (new->start + align - 1) & ~(align - 1);
+ new->start = round_up_pow2(new->start, align);
if (alignf)
alignf(alignf_data, new, size, align);
if (new->start < new->end && new->end - new->start + 1 >= size) {
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/6] lib/bitmap.c: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
` (4 preceding siblings ...)
2005-04-08 0:50 ` [PATCH 4/6] kernel/resource.c: use generic round_up_pow2() macro Nick Wilson
@ 2005-04-08 0:51 ` Nick Wilson
2005-04-08 0:52 ` [PATCH 6/6] mm/bootmem.c: " Nick Wilson
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:51 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Use the generic round_up_pow2() instead of a custom rounding method.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
bitmap.c | 3 +--
1 files changed, 1 insertion(+), 2 deletions(-)
Index: linux/lib/bitmap.c
===================================================================
--- linux.orig/lib/bitmap.c 2005-04-07 15:13:56.000000000 -0700
+++ linux/lib/bitmap.c 2005-04-07 15:46:15.000000000 -0700
@@ -289,7 +289,6 @@ EXPORT_SYMBOL(__bitmap_weight);
#define CHUNKSZ 32
#define nbits_to_hold_value(val) fls(val)
-#define roundup_power2(val,modulus) (((val) + (modulus) - 1) & ~((modulus) - 1))
#define unhex(c) (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10))
#define BASEDEC 10 /* fancier cpuset lists input in decimal */
@@ -316,7 +315,7 @@ int bitmap_scnprintf(char *buf, unsigned
if (chunksz == 0)
chunksz = CHUNKSZ;
- i = roundup_power2(nmaskbits, CHUNKSZ) - CHUNKSZ;
+ i = round_up_pow2(nmaskbits, CHUNKSZ) - CHUNKSZ;
for (; i >= 0; i -= CHUNKSZ) {
chunkmask = ((1ULL << chunksz) - 1);
word = i / BITS_PER_LONG;
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 6/6] mm/bootmem.c: use generic round_up_pow2() macro
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
` (5 preceding siblings ...)
2005-04-08 0:51 ` [PATCH 5/6] lib/bitmap.c: " Nick Wilson
@ 2005-04-08 0:52 ` Nick Wilson
6 siblings, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 0:52 UTC (permalink / raw)
To: linux-kernel, akpm, rddunlap
From: Nick Wilson <njw@osdl.org>
Use the generic round_up_pow2() instead of a custom rounding method.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
bootmem.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
Index: linux/mm/bootmem.c
===================================================================
--- linux.orig/mm/bootmem.c 2005-04-07 15:13:56.000000000 -0700
+++ linux/mm/bootmem.c 2005-04-07 15:46:41.000000000 -0700
@@ -57,7 +57,7 @@ static unsigned long __init init_bootmem
pgdat->pgdat_next = pgdat_list;
pgdat_list = pgdat;
- mapsize = (mapsize + (sizeof(long) - 1UL)) & ~(sizeof(long) - 1UL);
+ mapsize = round_up_pow2(mapsize, sizeof(long));
bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT);
bdata->node_boot_start = (start << PAGE_SHIFT);
bdata->node_low_pfn = end;
@@ -178,7 +178,7 @@ __alloc_bootmem_core(struct bootmem_data
} else
preferred = 0;
- preferred = ((preferred + align - 1) & ~(align - 1)) >> PAGE_SHIFT;
+ preferred = round_up_pow2(preferred, align) >> PAGE_SHIFT;
preferred += offset;
areasize = (size+PAGE_SIZE-1)/PAGE_SIZE;
incr = align >> PAGE_SHIFT ? : 1;
@@ -219,7 +219,7 @@ found:
*/
if (align < PAGE_SIZE &&
bdata->last_offset && bdata->last_pos+1 == start) {
- offset = (bdata->last_offset+align-1) & ~(align-1);
+ offset = round_up_pow2(bdata->last_offset, align);
BUG_ON(offset > PAGE_SIZE);
remaining_size = PAGE_SIZE-offset;
if (size < remaining_size) {
_
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] add generic round_up_pow2() macro
2005-04-08 0:50 ` [PATCH 0/6] add " Andrew Morton
@ 2005-04-08 9:57 ` P
2005-04-08 10:32 ` P
2005-04-08 18:50 ` [PATCH] Use ALIGN to remove duplicate code Nick Wilson
1 sibling, 1 reply; 11+ messages in thread
From: P @ 2005-04-08 9:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: Nick Wilson, linux-kernel, rddunlap
Andrew Morton wrote:
> Nick Wilson <njw@osdl.org> wrote:
>
>>The first patch adds a generic round_up_pow2() macro to kernel.h. The
>> remaining patches modify a few files to make use of the new macro.
>
>
> We already have ALIGN() and roundup_pow_of_two().
cool. It doesn't handle x={0,1} though.
Maybe we should have:
static inline unsigned long __attribute_const__
__roundup_pow_of_two(unsigned long x)
{
return (1UL << fls(x - 1));
}
static inline unsigned long __attribute_const__
roundup_pow_of_two(unsigned long x)
{
return (unlikely(x<2)?2:__roundup_pow_of_two(x));
}
--
Pádraig Brady - http://www.pixelbeat.org
--
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] add generic round_up_pow2() macro
2005-04-08 9:57 ` P
@ 2005-04-08 10:32 ` P
0 siblings, 0 replies; 11+ messages in thread
From: P @ 2005-04-08 10:32 UTC (permalink / raw)
To: Andrew Morton; +Cc: Nick Wilson, linux-kernel, rddunlap
P@draigBrady.com wrote:
> Andrew Morton wrote:
>
>> Nick Wilson <njw@osdl.org> wrote:
>>
>>> The first patch adds a generic round_up_pow2() macro to kernel.h. The
>>> remaining patches modify a few files to make use of the new macro.
>>
>>
>>
>> We already have ALIGN() and roundup_pow_of_two().
>
>
> cool. It doesn't handle x={0,1} though.
Well I should clarify.
2^0==1 is a special case that you probably
don't want as a result from the macro?
--
Pádraig Brady - http://www.pixelbeat.org
--
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] Use ALIGN to remove duplicate code
2005-04-08 0:50 ` [PATCH 0/6] add " Andrew Morton
2005-04-08 9:57 ` P
@ 2005-04-08 18:50 ` Nick Wilson
1 sibling, 0 replies; 11+ messages in thread
From: Nick Wilson @ 2005-04-08 18:50 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, rddunlap
On Thu, Apr 07, 2005 at 05:50:42PM -0700, Andrew Morton wrote:
> Nick Wilson <njw@osdl.org> wrote:
> > The first patch adds a generic round_up_pow2() macro to kernel.h. The
> > remaining patches modify a few files to make use of the new macro.
>
> We already have ALIGN() and roundup_pow_of_two().
Andrew,
This patch makes use of ALIGN() to remove duplicate round-up code.
Signed-off-by: Nick Wilson <njw@osdl.org>
---
include/linux/a.out.h | 2 +-
kernel/resource.c | 2 +-
lib/bitmap.c | 3 +--
mm/bootmem.c | 6 +++---
4 files changed, 6 insertions(+), 7 deletions(-)
Index: linux/include/linux/a.out.h
===================================================================
--- linux.orig/include/linux/a.out.h 2005-04-08 10:59:14.000000000 -0700
+++ linux/include/linux/a.out.h 2005-04-08 11:00:40.000000000 -0700
@@ -138,7 +138,7 @@ enum machine_type {
#endif
#endif
-#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+#define _N_SEGMENT_ROUND(x) ALIGN(x, SEGMENT_SIZE)
#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
Index: linux/kernel/resource.c
===================================================================
--- linux.orig/kernel/resource.c 2005-04-08 10:59:36.000000000 -0700
+++ linux/kernel/resource.c 2005-04-08 11:00:50.000000000 -0700
@@ -263,7 +263,7 @@ static int find_resource(struct resource
new->start = min;
if (new->end > max)
new->end = max;
- new->start = (new->start + align - 1) & ~(align - 1);
+ new->start = ALIGN(new->start, align);
if (alignf)
alignf(alignf_data, new, size, align);
if (new->start < new->end && new->end - new->start + 1 >= size) {
Index: linux/lib/bitmap.c
===================================================================
--- linux.orig/lib/bitmap.c 2005-04-08 10:59:40.000000000 -0700
+++ linux/lib/bitmap.c 2005-04-08 11:00:59.000000000 -0700
@@ -289,7 +289,6 @@ EXPORT_SYMBOL(__bitmap_weight);
#define CHUNKSZ 32
#define nbits_to_hold_value(val) fls(val)
-#define roundup_power2(val,modulus) (((val) + (modulus) - 1) & ~((modulus) - 1))
#define unhex(c) (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10))
#define BASEDEC 10 /* fancier cpuset lists input in decimal */
@@ -316,7 +315,7 @@ int bitmap_scnprintf(char *buf, unsigned
if (chunksz == 0)
chunksz = CHUNKSZ;
- i = roundup_power2(nmaskbits, CHUNKSZ) - CHUNKSZ;
+ i = ALIGN(nmaskbits, CHUNKSZ) - CHUNKSZ;
for (; i >= 0; i -= CHUNKSZ) {
chunkmask = ((1ULL << chunksz) - 1);
word = i / BITS_PER_LONG;
Index: linux/mm/bootmem.c
===================================================================
--- linux.orig/mm/bootmem.c 2005-04-08 10:59:43.000000000 -0700
+++ linux/mm/bootmem.c 2005-04-08 11:05:45.000000000 -0700
@@ -57,7 +57,7 @@ static unsigned long __init init_bootmem
pgdat->pgdat_next = pgdat_list;
pgdat_list = pgdat;
- mapsize = (mapsize + (sizeof(long) - 1UL)) & ~(sizeof(long) - 1UL);
+ mapsize = ALIGN(mapsize, sizeof(long));
bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT);
bdata->node_boot_start = (start << PAGE_SHIFT);
bdata->node_low_pfn = end;
@@ -178,7 +178,7 @@ __alloc_bootmem_core(struct bootmem_data
} else
preferred = 0;
- preferred = ((preferred + align - 1) & ~(align - 1)) >> PAGE_SHIFT;
+ preferred = ALIGN(preferred, align) >> PAGE_SHIFT;
preferred += offset;
areasize = (size+PAGE_SIZE-1)/PAGE_SIZE;
incr = align >> PAGE_SHIFT ? : 1;
@@ -219,7 +219,7 @@ found:
*/
if (align < PAGE_SIZE &&
bdata->last_offset && bdata->last_pos+1 == start) {
- offset = (bdata->last_offset+align-1) & ~(align-1);
+ offset = ALIGN(bdata->last_offset, align);
BUG_ON(offset > PAGE_SIZE);
remaining_size = PAGE_SIZE-offset;
if (size < remaining_size) {
_
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-04-08 18:50 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-08 0:44 [PATCH 0/6] add generic round_up_pow2() macro Nick Wilson
2005-04-08 0:48 ` [PATCH 1/6] include/linux/kernel.h: use " Nick Wilson
2005-04-08 0:49 ` [PATCH 2/6] " Nick Wilson
2005-04-08 0:50 ` [PATCH 3/6] include/linux/a.out.h: " Nick Wilson
2005-04-08 0:50 ` [PATCH 0/6] add " Andrew Morton
2005-04-08 9:57 ` P
2005-04-08 10:32 ` P
2005-04-08 18:50 ` [PATCH] Use ALIGN to remove duplicate code Nick Wilson
2005-04-08 0:50 ` [PATCH 4/6] kernel/resource.c: use generic round_up_pow2() macro Nick Wilson
2005-04-08 0:51 ` [PATCH 5/6] lib/bitmap.c: " Nick Wilson
2005-04-08 0:52 ` [PATCH 6/6] mm/bootmem.c: " Nick Wilson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).