* [patch 1/1] combine two adjacent mtrr region with the same type @ 2008-10-09 8:21 bibo mao 2008-10-09 15:54 ` Yinghai Lu 0 siblings, 1 reply; 3+ messages in thread From: bibo mao @ 2008-10-09 8:21 UTC (permalink / raw) To: linux-kernel; +Cc: akpm This patch is to combine two adjacent mtrr region with the same type. kernel/cpu/mtrr/main.c | 17 +++++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) Signed-off-by: bibo mao <bibo.mao@gmail.com> ------------------------------------------------------------------------------- diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c index 6e212f3..c3adf83 100644 --- a/arch/x86/kernel/cpu/mtrr/main.c +++ b/arch/x86/kernel/cpu/mtrr/main.c @@ -305,7 +305,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, { int i, j, replace, error; mtrr_type ltype; - unsigned long lbase, lsize; + unsigned long lbase, lsize, newbase; if (!mtrr_if) return -ENXIO; @@ -344,7 +344,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, mutex_lock(&mtrr_mutex); for (i = 0; i < num_var_ranges; ++i) { mtrr_if->get(i, &lbase, &lsize, <ype); - if (!lsize || base > lbase + lsize - 1 || base + size - 1 < lbase) + if (!lsize || base > lbase + lsize || base + size < lbase) continue; /* At this point we know there is some kind of overlap/enclosure */ if (base < lbase || base + size - 1 > lbase + lsize - 1) { @@ -356,6 +356,19 @@ int mtrr_add_page(unsigned long base, unsigned long size, } else if (types_compatible(type, ltype)) continue; + } else if ((base == lbase + lsize) || (lbase ==base + size)) { + if (type != ltype) + continue; + /* New region adjacent with an existing region */ + newbase = (base < lbase) ? base : lbase; + if (!mtrr_if->validate_add_page(newbase,lsize + size,type) && + mtrr_if->get_free_region(newbase, lsize + size, replace)>=0) { + base = newbase; + size += lsize; + replace = i; + continue; + } else + continue; } printk(KERN_WARNING "mtrr: 0x%lx000,0x%lx000 overlaps existing" ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch 1/1] combine two adjacent mtrr region with the same type 2008-10-09 8:21 [patch 1/1] combine two adjacent mtrr region with the same type bibo mao @ 2008-10-09 15:54 ` Yinghai Lu 2008-10-10 3:59 ` bmao 0 siblings, 1 reply; 3+ messages in thread From: Yinghai Lu @ 2008-10-09 15:54 UTC (permalink / raw) To: bibo mao; +Cc: linux-kernel, akpm bibo mao wrote: > This patch is to combine two adjacent mtrr region with the same type. > > kernel/cpu/mtrr/main.c | 17 +++++++++++++++-- > 3 files changed, 15 insertions(+), 2 deletions(-) > > Signed-off-by: bibo mao <bibo.mao@gmail.com> > > ------------------------------------------------------------------------------- > diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c > index 6e212f3..c3adf83 100644 > --- a/arch/x86/kernel/cpu/mtrr/main.c > +++ b/arch/x86/kernel/cpu/mtrr/main.c > @@ -305,7 +305,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, > { > int i, j, replace, error; > mtrr_type ltype; > - unsigned long lbase, lsize; > + unsigned long lbase, lsize, newbase; > > if (!mtrr_if) > return -ENXIO; > @@ -344,7 +344,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, > mutex_lock(&mtrr_mutex); > for (i = 0; i < num_var_ranges; ++i) { > mtrr_if->get(i, &lbase, &lsize, <ype); > - if (!lsize || base > lbase + lsize - 1 || base + size - 1 < lbase) > + if (!lsize || base > lbase + lsize || base + size < lbase) > continue; > /* At this point we know there is some kind of overlap/enclosure */ > if (base < lbase || base + size - 1 > lbase + lsize - 1) { > @@ -356,6 +356,19 @@ int mtrr_add_page(unsigned long base, unsigned long size, > } > else if (types_compatible(type, ltype)) > continue; > + } else if ((base == lbase + lsize) || (lbase ==base + size)) { > + if (type != ltype) > + continue; this path seems not right... do you need if (ltype != type) { if (types_compatible(type, ltype)) continue; printk (KERN_WARNING "mtrr: type mismatch for %lx000,%lx000 old: %s new: %s\n", base, size, mtrr_attrib_to_str(ltype), mtrr_attrib_to_str(type)); goto out; } ? > + /* New region adjacent with an existing region */ > + newbase = (base < lbase) ? base : lbase; > + if (!mtrr_if->validate_add_page(newbase,lsize + size,type) && > + mtrr_if->get_free_region(newbase, lsize + size, replace)>=0) { > + base = newbase; > + size += lsize; > + replace = i; > + continue; > + } else > + continue; > } > printk(KERN_WARNING > "mtrr: 0x%lx000,0x%lx000 overlaps existing" better to have some test case... YH ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch 1/1] combine two adjacent mtrr region with the same type 2008-10-09 15:54 ` Yinghai Lu @ 2008-10-10 3:59 ` bmao 0 siblings, 0 replies; 3+ messages in thread From: bmao @ 2008-10-10 3:59 UTC (permalink / raw) To: Yinghai Lu Cc: bibo mao, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Yinghai Lu wrote: > bibo mao wrote: >> This patch is to combine two adjacent mtrr region with the same type. >> >> kernel/cpu/mtrr/main.c | 17 +++++++++++++++-- >> 3 files changed, 15 insertions(+), 2 deletions(-) >> >> Signed-off-by: bibo mao <bibo.mao@gmail.com> >> >> ------------------------------------------------------------------------------- >> diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c >> index 6e212f3..c3adf83 100644 >> --- a/arch/x86/kernel/cpu/mtrr/main.c >> +++ b/arch/x86/kernel/cpu/mtrr/main.c >> @@ -305,7 +305,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, >> { >> int i, j, replace, error; >> mtrr_type ltype; >> - unsigned long lbase, lsize; >> + unsigned long lbase, lsize, newbase; >> >> if (!mtrr_if) >> return -ENXIO; >> @@ -344,7 +344,7 @@ int mtrr_add_page(unsigned long base, unsigned long size, >> mutex_lock(&mtrr_mutex); >> for (i = 0; i < num_var_ranges; ++i) { >> mtrr_if->get(i, &lbase, &lsize, <ype); >> - if (!lsize || base > lbase + lsize - 1 || base + size - 1 < lbase) >> + if (!lsize || base > lbase + lsize || base + size < lbase) >> continue; >> /* At this point we know there is some kind of overlap/enclosure */ >> if (base < lbase || base + size - 1 > lbase + lsize - 1) { >> @@ -356,6 +356,19 @@ int mtrr_add_page(unsigned long base, unsigned long size, >> } >> else if (types_compatible(type, ltype)) >> continue; >> + } else if ((base == lbase + lsize) || (lbase ==base + size)) { >> + if (type != ltype) >> + continue; > this path seems not right... > > do you need > > if (ltype != type) { > if (types_compatible(type, ltype)) > continue; > printk (KERN_WARNING "mtrr: type mismatch for %lx000,%lx000 old: %s new: %s\n", > base, size, mtrr_attrib_to_str(ltype), > mtrr_attrib_to_str(type)); > goto out; > } > ? This warning info is for two enclosed mtrr region, but it is adjacent here. Here is no overlapped mtrr region even. > > > > >> + /* New region adjacent with an existing region */ >> + newbase = (base < lbase) ? base : lbase; >> + if (!mtrr_if->validate_add_page(newbase,lsize + size,type) && >> + mtrr_if->get_free_region(newbase, lsize + size, replace)>=0) { >> + base = newbase; >> + size += lsize; >> + replace = i; >> + continue; >> + } else >> + continue; >> } >> printk(KERN_WARNING >> "mtrr: 0x%lx000,0x%lx000 overlaps existing" > > better to have some test case... > > YH > Here is test result: # echo "base=0x02000000 size=0x00800000 type=write-back" >| /proc/mtrr # echo "base=0x03000000 size=0x01000000 type=write-back" >| /proc/mtrr # cat /proc/mtrr reg00: base=0x02000000 ( 32MB), size= 8MB: write-back, count=1 reg01: base=0x03000000 ( 48MB), size= 16MB: write-back, count=1 # echo "base=0x02800000 size=0x00800000 type=write-back" >| /proc/mtrr # cat /proc/mtrr reg01: base=0x02000000 ( 32MB), size= 32MB: write-back, count=3 Without this patch, it will display with this result: reg00: base=0x02000000 ( 32MB), size= 8MB: write-back, count=1 reg01: base=0x03000000 ( 48MB), size= 16MB: write-back, count=1 reg02: base=0x02800000 ( 40MB), size= 8MB: write-back, count=1 thanks bibo,mao ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-10 4:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-10-09 8:21 [patch 1/1] combine two adjacent mtrr region with the same type bibo mao 2008-10-09 15:54 ` Yinghai Lu 2008-10-10 3:59 ` bmao
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox