Sponsored Content
Top Forums Programming Linux kernel code syntax doubt Post 302534370 by ygemici on Monday 27th of June 2011 05:19:11 PM
Old 06-27-2011
Quote:
Originally Posted by alister
I believe you are absolutely mistaken regarding this being a performance optimization. The cpu registers are the fastest, operating system-visible processor-storage locations available, faster than any level of cache and most definitely faster than main memory (RAM). Performance optimizations typically attempt to stuff as many things into registers as possible.

I'm not a big hardware person, but if I'm not mistaken, the x86 32bit architecture has comparitively few registers. asmlinkage is a workaround for this. Note that the stack is not used for this purpose on any other platform. Except for x86 32-bit which includes the gcc function attribute code in the definition of asmlinkage, by default asmlinkage is nothing more than "extern C".

Regards,
Alister
Smilie
generally you are right.registers are faster therefore are part of the microprocessor.yes stack access is slower than register access.
Additional, CPU often access the stack and therefore stack(return addres of functions,parameters,registers,tmp infos,local variables..) datas usually is
saved in processor's cache.however cpu registers are very fast beceause of registers are very near and wired directly alu.So I meant just optimization not fast my fault.

i want to add some information about this issue.
asmlinkage tells to compiler that the arguments are on the stack(gcc takes it (i386 specific __attribute__((regparm(0))) and related in below asm code)
(actually,is a tag for assembly code convention for compiler (like asm/nasm/..))

# define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) provides like about below..
* userspace application executes
* (c) library routines puts arguments in registers from userspace.
( about register i want to tell something , since Linux 2.3.31 that is supported six system call parameters,but before
linux could handle 4(for some ver..5) system call parametres, if more than four arguments are needed, they are lef on the stack but i mentioned for new
version)
* enter kernel mode (executing trap --> int 0x80/sysenter) and executed kernel syscall handler(system_call() f)
* save current syscall number to eax.
* executed SAVE_ALL macro (%macro SAVE_ALL)
1) save address of kernel data(ds) and extra segment(to es)
2) all arguments(ebx,ecx,edx,esi,edi,ebp actually correct order will be reverse of this for C function call ) saves to stack
3) copy user_data_segment to ds register.
* %endmacro
* call (C) function (arguments are passed on the stack to c function (with asmlinkage))
* RESTORE_ALL(restores ebx, ecx, edx, esi, edi, ebp, eax, ds, es) and then go back to usermode (ret)

And asmlinkage format is like..
On i386
__attribute__((regparm(0)))
On ia64
__attribute__((syscall_linkage))

regards
ygemici
 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk syntax doubt - trailing 1 value

In the below awk syntax, what does the value '1' signify? awk '{....}1' file some eg: awk '{gsub(/]/,"")}1' awk 'BEGIN{ORS=""}1' awk '{ORS=(!(NR%5)?"":"\n")}1' (4 Replies)
Discussion started by: royalibrahim
4 Replies

2. Red Hat

Doubt on Linux console

Can anyone explain me the usage of momentary press, press and hold, Reset.. I usually use cold boot option which is used to boot the system. Any help on the other options is really helpful thanks in advance (5 Replies)
Discussion started by: rogerben
5 Replies

3. UNIX for Dummies Questions & Answers

Any tips/suggestions for a newbie beginning to read the Linux Kernel Source Code

Hi All, I recently downloaded the Linux kernel source code, added them all to a project in MS VC++ and plan to read through it so that I can improve the way I code, read/understand a large code database and hopefully contribute something to the development of the Linux OS. I have taken a... (3 Replies)
Discussion started by: clavian
3 Replies

4. Programming

Linux Kernel code "current" macro

I was going through the Linux code, i stuck with few inline assembly language code, I have tried online but in vain. Any help is much appreciated. Thanks. /* how to get the thread information struct from C */ static inline struct thread_info *current_thread_info(void) { struct... (3 Replies)
Discussion started by: kumaran_5555
3 Replies
td_thr_getgregs(3C_DB)					Threads Debugging Library Functions				    td_thr_getgregs(3C_DB)

NAME
td_thr_getgregs, td_thr_setgregs, td_thr_getfpregs, td_thr_setfpregs, td_thr_getxregsize, td_thr_getxregs, td_thr_setxregs - reading and writing thread registers in libc_db SYNOPSIS
cc [ flag... ] file... -lc_db [ library... ] #include <proc_service.h> #include <thread_db.h> td_err_e td_thr_getgregs(const td_thrhandle_t *th_p, prgregset_tgregset); td_err_e td_thr_setgregs(const td_thrhandle_t *th_p, prgregset_tgregset); td_err_e td_thr_getfpregs(const td_thrhandle_t *th_p, prfpregset_t *fpregset); td_err_e td_thr_setfpregs(const td_thrhandle_t *th_p, prfpregset_t *fpregset); td_err_e td_thr_getxregsize(const td_thrhandle_t *th_p, int *xregsize); td_err_e td_thr_getxregs(const td_thrhandle_t *th_p, prxregset_t *xregset); td_err_e td_thr_setxregs(const td_thrhandle_t *th_p, prxregset_t *xregset); DESCRIPTION
These functions read and write the register sets associated with thread th_p. The td_thr_getgregs() and td_thr_setgregs() functions get and set, respectively, the general registers of thread th_p. The td_thr_getfpregs() and td_thr_setfpregs() functions get and set, respectively, the thread's floating point register set. The td_thr_getxregsize(), td_thr_getxregs(), and td_thr_setxregs() functions are SPARC-specific. The td_thr_getxregsize() function returns in *xregsize the size of the architecture-dependent extra state registers. The td_thr_getxregs() and td_thr_setxregs() functions get and set, respectively, those extra state registers. On non-SPARC architectures, these functions return TD_NOXREGS. If the thread specified by th_p is currently executing on a lightweight process ( LWP), these functions read or write, respectively, the appropriate register set to the LWP using the imported interface. If the thread is not currently executing on an LWP, the floating point and extra state registers may cannot be read or written. Some of the general registers might also not be readable or writable, depending on the architecture, in which case td_thr_getfpregs() and td_thr_setfpregs() return TD_NOFPREGS and td_thr_getxregs() and td_thr_setxregs() will TD_NOXREGS. Calls to td_thr_getgregs() and td_thr_setgregs() succeed, but values returned for unreadable registers are undefined, val- ues specified for unwritable registers are ignored. In this instance, and TD_PARTIALREGS is returned. See the architecture-specific notes that follow regarding the registers that may be read and written for a thread not currently executing on an LWP. SPARC On a thread not currently assigned to an LWP, only %i0-%i7, %l0-%l7, %g7, %pc, and %sp (%o6) can be read or written. %pc and %sp refer to the program counter and stack pointer that the thread will have when it resumes execution. x86 Architecture On a thread not currently assigned to an LWP, only %pc, %sp, %ebp, %edi, %edi, and %ebx can be read. RETURN VALUES
TD_OK The call completed successfully. TD_BADTH An invalid thread handle was passed in. TD_DBERR A call to one of the imported interface routines failed. TD_PARTIALREGS Because the thread is not currently assigned to a LWP, not all registers were read or written. See DESCRIPTION for a dis- cussion about which registers are not saved when a thread is not assigned to an LWP. TD_NOFPREGS Floating point registers could not be read or written, either because the thread is not currently assigned to an LWP, or because the architecture does not have such registers. TD_NOXREGS Architecture-dependent extra state registers could not be read or written, either because the thread is not currently assigned to an LWP, or because the architecture does not have such registers, or because the architecture is not a SPARC architecture. TD_ERR A libc_db internal error occurred. ATTRIBUTES
See attributes(5) for description of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
libc_db(3LIB), attributes(5) SunOS 5.11 20 Oct 1998 td_thr_getgregs(3C_DB)
All times are GMT -4. The time now is 07:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy