Creating a vDSO: the Colonel's Other Chicken
And Now Some Special Sauce
gettimeofday(), a
special time variable is mapped into memory where the kernel updates it and the
userland (vDSO version) can read it. The kernel merely copies what it knows
about time into that variable, and when a vDSO is made, that call just reads the
information saving the overhead of crossing memory segments. The addition or
access of a kernel variable is fairly involved as compared to a basic vDSO
function, but because the purpose of a vDSO is to access kernel information, such
as that provided in variables, I probably should give a quick overview
of doing that.
For illustrative purposes, let's add a value that lives in kernel land but
is read from userland. Sure, I said earlier that this mystical number might
change and you should implement a function to return it. Well, you have a
function, but all you know now is the value and not what it might change to in
the future. Let's make the function return a value, nonconstant. Wow, this
use case is becoming really unusual. To elaborate, let's update this variable
as the kernel requests. The kernel will update the vDSO variables
in the update_vsyscall() function located in
linux-2.6.37/arch/x86/kernel.
If you were to declare it const int vnotb = 666;, the value captured there would
not be set (more on this later).
Let's define the value to be, in fact, the mysterious number of the beast
itself, which I will call vnotb. This number will reside in
kernel land, as so many other useful values, such as time, which the efficient
gettimeofday() vDSO will obtain. This is where the true magic of vDSOs lie.
Let's remain in linux-2.6.37/arch/x86/vdso and modify all the
goodies here. First, declare the variable via the
VEXTERN() macro. In
vextern.h, add your declaration alongside all the other declarations:
VEXTERN(vnotb)
This macro will create a variable that is a pointer to the value you care about
and is prefixed with vdso_. In essence, you have declared vnotb as
int *vdso_vnotb;.
vextern.h mentions that:
Any kernel variables used in the vDSO must be exported in the main kernel's vmlinux.lds.S/vsyscall.h/proper__section and put into vextern.h and be referenced as a pointer with vdso prefix. The main kernel later fills in the values (comment in linux-2.6.37/arch/x86/vdso/vextern.h).
Now that you have some of the vDSO code in place, the userland stuff and the
kernel-userland mapping, let's make use of it. In the function
vget_number_of_the_beast(), let's return the value:
notrace int __vdso_number_of_the_beast(void)
{
return *vdso_vnotb;
}
Don't forget to add the header that declares that value,
vextern.h as well as
an additional header that will resolve some data referenced by the latter,
vgtod.h:
#include <asm/vgtod.h>
#include "vextern.h"
To wrap things up, you need to let the kernel know about this variable so it
can pump data into it. You need the kernel to give userland a value.
Well, you
have it mapped at the address specified above, but that is rather
pointless,
unless Mr Sanders, the colonel, doesn't push some data into it. You need to
go up one directory (yes, this isn't the most trivial of processes). Hop
into linux-2.6.37/arch/x86/kernel. You need to let the linker know of this
value, so it can map between kernel and userland, so you probably should rock
that. Modify vmlinux.lds.S, and add the following after the
vgetcpu_mode
piece (note that adding it after or before
vgetcpu_mode isn't necessary, but it's
an easy place to find things):
.vnotb : AT(VLOAD(.vnotb)) {
*(.vnotb)
}
vnotb = VVIRT(.vnotb);
This links the vnotb symbol with the variable
vnotb.
This sets up the variable in the address space for kernel land to access
and write to. The macros above, AT,
VLOAD and VVIRT deal with modifying
addresses so that the proper piece of data, at the
vnotb, is referenced.
Now, you need to declare the value that the kernel land will write to. In linux-2.6.37/arch/x86/include/asm/vsyscall.h declare this puppy and its section that will be inserted via the above linker script entry you most recently added:
#define __section_vnotb __attribute__ ((unused,
↪__section__ (".vnotb"), aligned(16)))
In this file, as mentioned, you also will declare the kernel-land variable
to which
the kernel will write. To keep things slightly more readable, associate your
variable next to the vgetcpu_mode declaration:
extern int vnotb;
You also will define a value the kernel can read (I don't use this in my example, but if the kernel needs to read the value, this is the variable to read):
extern int __vnotb;
Now let's put this stuff in code and give it a value. The kernel will write the
value via the writable vnotb, and you also can read it from the shared memory
between kernel and userland via __vnotb. You will write the value in the
kernel-land version of the variable, which is writable. In
linux-2.6.37/arch/x86/kernel/vsyscall_64.c, preferably
after all of the #include headers and just after the piece: int __vgetcpu_mode
__section_vgetcpu_mode;, add the following:
int __vnotb __section_vnotb;
Remember, you did a trick with the linker setting the value. If you set the value globally, as you would for an extern, you would not get a value, the linker would override it. You need to set this value at runtime and not statically at compile time. To set this value as the kernel updates, modify the update_vsyscall() routine in linux-2.6.37/arch/x86/kernel/vsyscall_64.c with:
vnotb = 666;
This statement is defining the value declared previously in vsyscall.h.
Matt Davis is a software engineer on leave from his job in the US to pursue a PhD from the Computer Science Department at the University of Melbourne, where he is focusing his hackery toward the compiler field.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Speed Up Your Web Site with Varnish | Jun 19, 2013 |
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
- Speed Up Your Web Site with Varnish
- Containers—Not Virtual Machines—Are the Future Cloud
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Non-Linux FOSS: libnotify, OS X Style
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- RSS Feeds
- Reply to comment | Linux Journal
38 min 3 sec ago - Reply to comment | Linux Journal
4 hours 37 min ago - Yeah, user namespaces are
5 hours 54 min ago - Cari Uang
9 hours 25 min ago - user namespaces
12 hours 18 min ago - yea
12 hours 44 min ago - One advantage with VMs
15 hours 13 min ago - about info
15 hours 46 min ago - info
15 hours 47 min ago - info
15 hours 48 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
----- http://ai.vc/zd
----- http://ai.vc/zd -----
Hi,Dear Ladies and Gentlemen,
1. sport shoes : Jordan ,Nike, adidas, Puma, Gucci, LV, UGG , etc. including women shoes and kids shoes.
2. T-Shirts : BBC T-Shirts, Bape T-Shirts, Armani T-Shirts, Polo T-Shirts,etc.
3. Hoodies : Bape hoody, hoody, AFF hoody, GGG hoody, ED hoody ,etc.
4. Jeans : Levis jeans , Gucci jeans, jeans, Bape jeans , DG jeans ,etc.
----- http://ai.vc/zd -----
----- http://ai.vc/zd -----
Service is our Lift.
enjoy yourself.
thank you!!
::∴★∵**☆.∴★∵**☆.∴★∵**☆.
█████.::∴★∵**☆.∴★∵**☆.
█田█田█::∴★∵**☆.∴★∵**☆.
█田█田█.∴★∵**☆.∴★∵**☆.
█田█田█∴★∵**☆.∴★∵**☆.
█田█田█.★∵**☆.∴★∵**☆.
█████.*******************
◢██□██◣.~~~~~*^_^*
Good content, I trust this is
Good content, I trust this is a good weblog about Wish to see refreshing content material next time. Thanks for sharing this publish with us. Keep it up.
hebergement audiotel voyance
Re : Creating a vDSO: the Colonel's Other Chicken
script code is my weakness and it is difficult for me to learn
but in this tutorial I will try hard to understand
thank you
why x86(32bit) does not have gettimeofday vdso
Very nice article. Thanks for explaining vdso concept.
Why x86(32bit) does not have gettimeofday vdso?
Only 64bit x86 has this call implemented. Why?
Does x86 32bit have limitations?