Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help getting a loop to not overwite important values

NorweedNorweed Member Posts: 5
What I'm trying to do here is add an overhead to every single system call. I can do this either by modifying ~320 C methods or I can do it in one place in i386 assembly land. As you might have guessed I'd much rather make this change in one place, the problem is I such at assembly and I'm having a hard time finding a resource that can help, so here I am asking for some help.

I'm working with the 2.6.22 kernel, and I'm trying to modify the arch/i386/kernel/entry.S file (I think that's the path). Right around like 370 or so is the main entry point after the processor interrupt has occurred. Here's what I have now:

[code]
# system call handler stub
ENTRY(system_call)
#THIS IS MY LOOP
movl %cx, 100000;
mylblb:
add %eax, %eax;
loop mylblb





RING0_INT_FRAME # can't unwind into user space anyway
pushl %eax # save orig_eax
CFI_ADJUST_CFA_OFFSET 4
SAVE_ALL
GET_THREAD_INFO(%ebp)

# system call tracing in operation / emulation
/* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSC
ALL_AUDIT),TI_flags(%ebp)
jnz syscall_trace_entry
cmpl $(nr_syscalls), %eax
jae syscall_badsys
syscall_call:
.
.
.
[/code]


As you can see I'm just adding a loop that does something minimal like add some values together. It fails miserably. I'm sure it's because I'm overwriting something important and not putting it back, but I don't know how to do that.

Any help would be GREATLY appreciated as I'm dead in the water here.


Disclaimer: Yes, this is part of a project for my CS master's degree, I'm not trying to get anyone to help me cheat on my homework, just need some help. The real part of this assignment is doing the analysis on the effects of this overhead. Just want to get that out there.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    First off, I'm not fully understanding what you are trying to do.
    But, some general tips:

    Usually if you want to execute code without modifying anything, you use the stack.
    So, in your routine, at any point after which the stack has been set up, you can use:
    [code]
    pushal
    # Do lots of things with the general registers here
    popal
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • NorweedNorweed Member Posts: 5
    Thanks, that's exactly the type of thing I was looking for.

    What I'm trying to do is add some overhead to ALL system calls. I figured that this would be the simplest place to do that. This loop I'm adding is imply intended to slow down all of the system calls a little bit.

    Am I going down the completely wrong path here?

    I added the pushal; and popal; commands and it looks like I'm still really affecting something I shouldn't be. Hmm.
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Thanks, that's exactly the type of thing I was looking for.
    :
    : What I'm trying to do is add some overhead to ALL system calls. I
    : figured that this would be the simplest place to do that. This loop
    : I'm adding is imply intended to slow down all of the system calls a
    : little bit.
    :
    : Am I going down the completely wrong path here?
    :

    Well, why would you want to do that? I guess a loop is the only way to do it, but it's a bit 'clumsy'.

    : I added the pushal; and popal; commands and it looks like I'm still
    : really affecting something I shouldn't be. Hmm.
    :

    Hmm, what kernel is this anyway? Unix?

    Anyway, you might want to do that delay stuff right before the call to the respective interrupt handlers... and, it's probably best to not delay a NMI (#2).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • NorweedNorweed Member Posts: 5
    If I do it in the system calls then I have to modify 320+ C functions and I'm really trying to avoid doing that.

    It's the Linux 2.6.22 kernel.


    I realize that this is clumsy. I'm not trying to make something faster, I'm writing a research paper on the effect of system call overhead on system performance. Basically I don't think that the system call delay is going to have a linearly declining effect on system performance.
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : If I do it in the system calls then I have to modify 320+ C
    : functions and I'm really trying to avoid doing that.
    :
    : It's the Linux 2.6.22 kernel.
    :
    :
    : I realize that this is clumsy. I'm not trying to make something
    : faster, I'm writing a research paper on the effect of system call
    : overhead on system performance. Basically I don't think that the
    : system call delay is going to have a linearly declining effect on
    : system performance.

    Well, I advise you put the loop somewhere behind the macro's. I don't know what they all do, but something like after the SAVE_ALL macro sounds like a right place to put your pushal/loop/popal code.

    Being slightly unfamilair with the Linux kernel, is this the entry point for all interrupts, or just the system interrupts? (INT 0x80 I believe it was?)

    I ask this because there are a lot of hardware interrupts generated (probably far more than software interrupts), and creating overhead for these too would probably slow the system down. Depending on the overhead, this could be considerable.

    I doubt you'll notice any speed-difference when adding a little bit of overhead to the system calls, but it's kind of cool that you're running an experiment.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • NorweedNorweed Member Posts: 5
    Thank you so much for the help. The loop is still doing something bad somewhere, and I'm beyond useless at figuring this stuff out.

    This is just the software interrupt so I'm not slowing everything down. I might have to go pester our linux kernel guys here at work.

    Thank you so much for the help.
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Thank you so much for the help. The loop is still doing something
    : bad somewhere, and I'm beyond useless at figuring this stuff out.
    :
    : This is just the software interrupt so I'm not slowing everything
    : down. I might have to go pester our linux kernel guys here at work.
    :
    : Thank you so much for the help.
    :

    If you didn't manage to get further help yet, could you post the code you have currently, and if possible could you post the definitions of all the macro's that are used in this code, such as SAVE_ALL, RING0_INT_FRAME, and the others?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • steviegstevieg Member Posts: 1

    hmmm. very interesting thread....

    -steve

    : : Thank you so much for the help. The loop is still doing something
    : : bad somewhere, and I'm beyond useless at figuring this stuff out.
    : :
    : : This is just the software interrupt so I'm not slowing everything
    : : down. I might have to go pester our linux kernel guys here at work.
    : :
    : : Thank you so much for the help.
    : :
    :
    : If you didn't manage to get further help yet, could you post the
    : code you have currently, and if possible could you post the
    : definitions of all the macro's that are used in this code, such as
    : SAVE_ALL, RING0_INT_FRAME, and the others?
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

  • NorweedNorweed Member Posts: 5
    I'll get all the info posted this weekend, didn't forget about the thread, just want to make sure that I do a little research and due diligence first.
Sign In or Register to comment.