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
ppmtosixel(1)                                                 General Commands Manual                                                ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 06:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy