* [PATCH] x86/xen: Use DIV_ROUND_UP
@ 2016-06-29 15:00 Amitoj Kaur Chawla
2016-06-29 15:34 ` [Xen-devel] " Jan Beulich
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Amitoj Kaur Chawla @ 2016-06-29 15:00 UTC (permalink / raw)
To: boris.ostrovsky, david.vrabel, jgross, tglx, mingo, hpa, x86,
xen-devel, linux-kernel
Cc: julia.lawall
The kernel.h macro DIV_ROUND_UP performs the computation
(((n) + (d) - 1) /(d)) but is perhaps more readable.
The Coccinelle script used to make this change is as follows:
@haskernel@
@@
#include <linux/kernel.h>
@depends on haskernel@
expression n,d;
@@
(
- (n + d - 1) / d
+ DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+ DIV_ROUND_UP(n,d)
)
Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
arch/x86/xen/enlighten.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 880862c..6847512 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -591,7 +591,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
{
unsigned long va = dtr->address;
unsigned int size = dtr->size + 1;
- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
+ unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
unsigned long frames[pages];
int f;
@@ -640,7 +640,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
{
unsigned long va = dtr->address;
unsigned int size = dtr->size + 1;
- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
+ unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
unsigned long frames[pages];
int f;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Xen-devel] [PATCH] x86/xen: Use DIV_ROUND_UP
2016-06-29 15:00 [PATCH] x86/xen: Use DIV_ROUND_UP Amitoj Kaur Chawla
@ 2016-06-29 15:34 ` Jan Beulich
[not found] ` <5774068C02000078000F9DCB@suse.com>
2016-06-29 15:45 ` David Vrabel
2 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2016-06-29 15:34 UTC (permalink / raw)
To: Amitoj Kaur Chawla
Cc: david.vrabel, x86, tglx, julia.lawall, xen-devel,
boris.ostrovsky, mingo, Juergen Gross, linux-kernel, hpa
>>> On 29.06.16 at 17:00, <amitoj1606@gmail.com> wrote:
> --- a/arch/x86/xen/enlighten.c
> +++ b/arch/x86/xen/enlighten.c
> @@ -591,7 +591,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
> {
> unsigned long va = dtr->address;
> unsigned int size = dtr->size + 1;
> - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
> + unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
> unsigned long frames[pages];
> int f;
>
> @@ -640,7 +640,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
> {
> unsigned long va = dtr->address;
> unsigned int size = dtr->size + 1;
> - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
> + unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
> unsigned long frames[pages];
> int f;
>
Perhaps even more readable would be PFN_DOWN()?
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xen-devel] [PATCH] x86/xen: Use DIV_ROUND_UP
[not found] ` <5774068C02000078000F9DCB@suse.com>
@ 2016-06-29 15:35 ` Juergen Gross
0 siblings, 0 replies; 4+ messages in thread
From: Juergen Gross @ 2016-06-29 15:35 UTC (permalink / raw)
To: Jan Beulich, Amitoj Kaur Chawla
Cc: david.vrabel, x86, tglx, julia.lawall, xen-devel,
boris.ostrovsky, mingo, linux-kernel, hpa
On 29/06/16 17:34, Jan Beulich wrote:
>>>> On 29.06.16 at 17:00, <amitoj1606@gmail.com> wrote:
>> --- a/arch/x86/xen/enlighten.c
>> +++ b/arch/x86/xen/enlighten.c
>> @@ -591,7 +591,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
>> {
>> unsigned long va = dtr->address;
>> unsigned int size = dtr->size + 1;
>> - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
>> + unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
>> unsigned long frames[pages];
>> int f;
>>
>> @@ -640,7 +640,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
>> {
>> unsigned long va = dtr->address;
>> unsigned int size = dtr->size + 1;
>> - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
>> + unsigned pages = DIV_ROUND_UP(size, PAGE_SIZE);
>> unsigned long frames[pages];
>> int f;
>>
>
> Perhaps even more readable would be PFN_DOWN()?
Or PFN_UP() to be correct?
Juergen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xen-devel] [PATCH] x86/xen: Use DIV_ROUND_UP
2016-06-29 15:00 [PATCH] x86/xen: Use DIV_ROUND_UP Amitoj Kaur Chawla
2016-06-29 15:34 ` [Xen-devel] " Jan Beulich
[not found] ` <5774068C02000078000F9DCB@suse.com>
@ 2016-06-29 15:45 ` David Vrabel
2 siblings, 0 replies; 4+ messages in thread
From: David Vrabel @ 2016-06-29 15:45 UTC (permalink / raw)
To: Amitoj Kaur Chawla, boris.ostrovsky, david.vrabel, jgross, tglx,
mingo, hpa, x86, xen-devel, linux-kernel
Cc: julia.lawall
On 29/06/16 16:00, Amitoj Kaur Chawla wrote:
> The kernel.h macro DIV_ROUND_UP performs the computation
> (((n) + (d) - 1) /(d)) but is perhaps more readable.
>
> The Coccinelle script used to make this change is as follows:
> @haskernel@
> @@
>
> #include <linux/kernel.h>
>
> @depends on haskernel@
> expression n,d;
> @@
>
> (
> - (n + d - 1) / d
> + DIV_ROUND_UP(n,d)
> |
> - (n + (d - 1)) / d
> + DIV_ROUND_UP(n,d)
> )
Applied to for-linus-4.8, thanks.
PFN_UP/DOWN() are for converting addresses to PFNs. DIV_ROUND_UP() is
clearer when converting sizes to numbers of pages (as demonstrated by
the incorrect suggestion to use PFN_DOWN()).
David
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-29 15:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-29 15:00 [PATCH] x86/xen: Use DIV_ROUND_UP Amitoj Kaur Chawla
2016-06-29 15:34 ` [Xen-devel] " Jan Beulich
[not found] ` <5774068C02000078000F9DCB@suse.com>
2016-06-29 15:35 ` Juergen Gross
2016-06-29 15:45 ` David Vrabel
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).