MorphOS tc_Launch / tc_Switch
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Okay, I already published my question on a mailing list but it seems that all
    MorphOS coders are busy so that no one did reply till now ( shame on you for
    being busy, by the way ;-) ).
    In order to implement "clock()" I need to know if it is possible to use the task
    entries tc_Launch and tc_Switch under MorphOS 1.x and 2.x.
    Unfortunately, I cannot lay my hands on the MorphOS programming
    documentation (anyone with a clue where it can be found?) so I only have
    the include files and there is stated that both entries are obsolete. If they are
    obsolete, I guess that there is a new mechanism in order to get informed
    when a task switch occurs? Unfortunately, because of the lacking
    documentation, I don't know where to look. Can some one point me in the
    right direction?

    Thanks in advance.
  • »30.09.09 - 19:18
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    tokai
    Posts: 1289 from 2003/2/25
    From: binaryriot
    We have special functions for that. No need to poke system structures.

    NewGetTaskAttr() ... check <exec/task.h> or/and <exec/system.h>

    I guess TASKINFOTYPE_AGETICKS or TASKINFOTIME_CPUTIME is what you want.
    Not sure what clock() is doing exactly... or what do you want to use it
    for; f.ex. for measuring time distances there are other ways too.




    [ Edited by tokai on 2009/9/30 20:25 ]
  • »30.09.09 - 19:24
    Profile Visit Website
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Quote:

    We have special functions for that. No need to poke system structures.



    I have already feared that. ;-)


    Quote:

    NewGetTaskAttr() ... check <exec/task.h> or/and <exec/system.h>



    Already checked before I did ask. Unfortunately, with no documentation
    on my side it's not clear what they are good for.


    Quote:

    I guess TASKINFOTYPE_AGETICKS or TASKINFOTIME_CPUTIME is what
    you want.



    Thanks. Can you give me some more details about their functions? What
    amount is returned and especially, what will be counted?
    I already stumbled over TASKINFO_LAUNCHTIMETICKS and
    SYSTEMINFO_LAUNCHTIMETICKS but I don't know what they are good
    for.
    I can only guess.


    Quote:

    Not sure what clock() is doing exactly... or what do you want to use it
    for; f.ex. for measuring time distances there are other ways too.



    clock_t clock ( void);

    Returns the number of clock ticks elapsed since the program was launched.


    With that, for example, a Delay(50) call would have no influence on the
    value returned by clock(), because it really only takes into account the
    time the task is up, running and especially performing something. In case
    an asynchronous IO is made, it won't affect the returned value either.
    With that one is able to determine the time consumed by the task by
    ignoring the time which will be spent in devices (unless IOF_QUICK is set)
    or in the DOS, where the task is sent asleep and at the earliest awakes
    when the IO/packet is completed.

    Normally clock() returns 50 ticks for an entire second but that value differs
    from implementation to implementation. Using SAS/C for example,
    TICKS_PER_SEC came to 1000.

    So, my question is what TAG I should choose?


    Thanks in advance.
  • »30.09.09 - 21:26
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    tokai
    Posts: 1289 from 2003/2/25
    From: binaryriot
    TASKINFOTYPE_CPUTIME you want then. It's bascially the amount of cpu ticks your application has used. While AGETICKS would be the amount of cpu ticks since program start.


    you get it like this:

    UQUAD tmp;
    NewGetTaskAttr(FindTask(NULL), &tmp, sizeof(tmp), TASKINFOTYPE_CPUTIME, TAG_DONE);


    and to get the amount of CPU ticks per second you do (e.g. at start of program):

    ULONG tmp2;
    NewGetSystemAttr(&tmp2, sizeof(tmp2), SYSTEMINFOTYPE_TBCLOCKFREQUENCY, TAG_DONE);


    the rest is simple math then ;)

    UQUAD cputimeusedinseconds = (tmp / ((UQUAD)tmp2));


    if you need a different scale you can divide tmp2 for your needs, i guess.


    Hope that's what you need and it helps. ;)
  • »30.09.09 - 22:13
    Profile Visit Website
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Quote:

    TASKINFOTYPE_CPUTIME you want then. It's bascially the amount
    of cpu ticks your application has used. While AGETICKS would be the
    amount of cpu ticks since program start.



    Okay, then I will use TASKINFOTYPE_CPUTIME.


    Quote:

    you get it like this:

    ...



    Thanks, examples are always welcome. :-)


    Quote:

    the rest is simple math then ;)



    Ouch, I am a computer, hence I cannot add one and one... ;-)


    Quote:

    Hope that's what you need and it helps. ;)



    Indeed. It will help me a lot! Thanks for your answers!
  • »01.10.09 - 17:24
    Profile
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Hi,

    one more question.

    I need to count how many interruptions the Task-scheduler enacted for the
    task in question.
    That is, on other platforms I increase a counter everytime "tc_Switch()" is
    called.

    Is TASKINFOTYPE_HITCOUNT designed for it?

    Thanks in advance.
  • »04.10.09 - 14:34
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    tokai
    Posts: 1289 from 2003/2/25
    From: binaryriot
    No, you want this:

    either total:
    TASKINFOTYPE_VOLUNTARYCSW
    TASKINFOTYPE_INVOLUNTARYCSW

    or for the last second:
    TASKINFOTYPE_LASTSECVOLUNTARYCSW
    TASKINFOTYPE_LASTSECINVOLUNTARYCSW

    CSW == context switch
  • »04.10.09 - 15:03
    Profile Visit Website
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Voluntary Context Switch?

    May I asked who thinks so laterally? ;-)
    Not in hundreds of years I would have associated VOLUNTARY_CSW with
    performed task switches!
    Even on Linux (I hate Linux, by the way) they use "context_swtch" or
    something that sounds like this (can't remember well).
    In addition, if I am right, voluntary and involuntary context switches mean
    something different than a simple task switch, they are meant for the
    outsourced work (giving up the processor explicitly (Wait() = voluntarily) and
    by handing over work (IO requests = involuntarily)).
    I can be mistaken but that's unlikely since I have a good memory (okay, it's an
    oxymoron... ( :-) ). :-}

    Never mind, now I know what to do and that I urgently need the MorphOS
    SDK-documentation for Exec!

    Thanks for your answer and explanation.
  • »04.10.09 - 18:25
    Profile
  • MorphOS Developer
    Krashan
    Posts: 1107 from 2003/6/11
    From: Białystok...
    Sending an I/O request is a voluntary context switch too, as Wait() is called in the context of your process. Unvoluntary switch happens when the task scheduler decides the time for your task is over for current period.
  • »04.10.09 - 19:36
    Profile Visit Website
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    Quote:

    Sending an I/O request is a voluntary context switch too, as Wait()
    is called in the context of your process.



    My confusion started because I never encountered before the statement
    'voluntary context switch' in relation with operating systems which don't
    offer threads in the kernel.
    In contrast to you and others, I did interpret 'voluntary' till now as a thread
    that put itself explicitly to sleep, i.e. on MorphOS the closest I can think of
    would be calling out of the program flow Wait(), but not by a device
    driver, which calls Wait() for me in the context of my process. This I would
    have equated with 'involuntary'.

    Quote:

    Unvoluntary switch happens when the task scheduler decides the
    time for your task is over for current period.



    Round-robin.

    But now I understand how they have been implemented for MorphOS.

    Thanks.
  • »05.10.09 - 21:33
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    jcmarcos
    Posts: 1178 from 2003/3/13
    From: Pinto, Madrid ...
    Fascinating read... What are you cooking, Jolo?
  • »06.10.09 - 08:33
    Profile
  • Just looking around
    Jolo
    Posts: 12 from 2006/10/7
    It is merely a simple mini-project, "clock()".
    Because I also need a special add-on which "clock()" doesn't offer, in order to
    be able to do special measurements, I had to ask again. That's all.

    Sorry to disappoint you.
  • »07.10.09 - 18:47
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    jcmarcos
    Posts: 1178 from 2003/3/13
    From: Pinto, Madrid ...
    Quote:

    Jolo wrote:
    It is merely a simple mini-project, "clock()". Sorry to disappoint you.


    I'm not dissapointed (sorry to dissapoint you in turn :-) ). It's very nice to read such in-depth discussions. Even if I don't understand them completely, it's indeed very nice to see this kind of feedback between a developer and a MorphOS team member.
    When the question is interesting, the Team always answers.
  • »08.10.09 - 08:05
    Profile