2005-10-09 12:02:38

by Vivek Kutal

[permalink] [raw]
Subject: Need for SHIFT and MASK

Hi ,
While browsing through the code i came across macros like SHIFT , MASK
, SIZE which are used in conversion from linear address to physical
address
but this is the job of the processor (address translation) then why do
we have these macros
can anyone please explain.



--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com

"Live as if you were to die tomorrow. Learn as if you were to live forever."


2005-10-09 12:23:45

by Ingo Oeser

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

Hi Vivek,

On Sunday 09 October 2005 14:02, Vivek Kutal wrote:
> While browsing through the code i came across macros like SHIFT , MASK
> , SIZE which are used in conversion from linear address to physical
> address
> but this is the job of the processor (address translation) then why do
> we have these macros
> can anyone please explain.

This is usally table driven and someone has to set up
this "Page Translation Tables". That's a job of the Linux kernel.

Just use sth. like Google to find out how it works
or go to the library and read some books on OS design
and virtual memory management.

Happy Studying!


Regards

Ingo Oeser


Attachments:
(No filename) (641.00 B)
(No filename) (189.00 B)
Download all attachments

2005-10-09 18:41:01

by Vivek Kutal

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

Hi Ingo,

> This is usally table driven and someone has to set up
> this "Page Translation Tables". That's a job of the Linux kernel.

Yes setting up the page table entries is the job of the kernel , but
for that we need to put the physical add. of the page and some bits
(present,access writes etc) in the entry, once it is done the main job
of translation which requires the masking and shifting is done by the
processor whenever that page is referenced .
so why these macros are present in the kernel?


--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com

"Live as if you were to die tomorrow. Learn as if you were to live forever."

2005-10-10 00:21:17

by Fawad Lateef

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

On 10/9/05, Vivek Kutal <[email protected]> wrote:
>
> > This is usally table driven and someone has to set up
> > this "Page Translation Tables". That's a job of the Linux kernel.
>
> Yes setting up the page table entries is the job of the kernel , but
> for that we need to put the physical add. of the page and some bits
> (present,access writes etc) in the entry, once it is done the main job
> of translation which requires the masking and shifting is done by the
> processor whenever that page is referenced .
> so why these macros are present in the kernel?
>
>

The setting of the Page Translation Tables are done by the Kernel, and
processor actually do the traversing over those page table entries
(PGD, PMD, PTE) to get the physical address of the page and then add
the last 12-bits of virtual/linear address to get to the physical
address .....

And as far as SHIFT, MASK, SIZE macros are concerned they are used in
creating Page Translation Tables and also used to get the translation
from linear to physical, SIZE macro used to get the current PAGE_SIZE,
SHIFT can be used to get PFN etc in Kernel Code ....

(I might not able to explain, just b/c I think your question is not so
clear to me !!!). You better study the stuffs and search in the kernel
code for those SHIFT, MASK, SIZE macros and you will see where they
are needed and used !!!!!


--
Fawad Lateef

2005-10-10 13:13:38

by Vivek Kutal

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

> And as far as SHIFT, MASK, SIZE macros are concerned they are used in
> creating Page Translation Tables and also used to get the translation
> from linear to physical

how are these macros used to create page translation tables (functions
like pgd_alloc(), pmd_alloc() & pte_alloc() are used for this
purpose)and the translation (virtual/linear to physical)is done by
the processor and not by the OS.


--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com

"Live as if you were to die tomorrow. Learn as if you were to
live forever."

2005-10-10 14:38:31

by Denis Vlasenko

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

On Sunday 09 October 2005 21:40, Vivek Kutal wrote:
> Hi Ingo,
>
> > This is usally table driven and someone has to set up
> > this "Page Translation Tables". That's a job of the Linux kernel.
>
> Yes setting up the page table entries is the job of the kernel , but
> for that we need to put the physical add. of the page and some bits
> (present,access writes etc) in the entry, once it is done the main job
> of translation which requires the masking and shifting is done by the
> processor whenever that page is referenced .
> so why these macros are present in the kernel?

They are needed. You can remome them.

NB: joke tags are invisible, but they are there.
--
vda

2005-10-10 16:49:40

by Fawad Lateef

[permalink] [raw]
Subject: Re: Need for SHIFT and MASK

On 10/10/05, Vivek Kutal <[email protected]> wrote:
> > And as far as SHIFT, MASK, SIZE macros are concerned they are used in
> > creating Page Translation Tables and also used to get the translation
> > from linear to physical
>
> how are these macros used to create page translation tables (functions
> like pgd_alloc(), pmd_alloc() & pte_alloc() are used for this
> purpose)and the translation (virtual/linear to physical)is done by
> the processor and not by the OS.
>
>

Actually I don't mean by mentioning "SHIFT, MASK, SZIE macros are used
in creating Page Translation Table" that you will see them in
pgd_alloc() etc but they are used in many memory initialization
fucntions at the boot time ...... and for example look
http://lxr.linux.no/source/arch/i386/mm/init.c#L207 !!!!!! These
Macros are might be there for the compatibility reasons tooo as you
can see the PAGE_SIZE can be changed but if you use PAGE_SIZE in every
module/place you won't be concerned about the actual size of the page
at that moment or in Architecture ...........


--
Fawad Lateef