On 07/28/2011 12:10 AM, Cyril Hrubis wrote:
> Hi!
>> +#define RUSAGE_THREAD 1
>
> Shouldn't this be set in system headers?
>
> And even if not, it probably would be on newer systems so better way
> should be:
>
> #ifndef RUSAGE_THREAD
> #define RUSAGE_THREAD 1
> #endif
corrected.
>
>> +static void busyloop(int wait);
>> +static void setup(void);
>> +static void cleanup(void);
>> +
>> +int main(int argc, char *argv[])
>> +{
>> + struct rusage usage;
>> + unsigned long ulast, udelta, slast, sdelta;
>> + int i, lc;
>> + char *msg;
>> +
>> + msg = parse_opts(argc, argv, NULL, NULL);
>> + if (msg != NULL)
>> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
>> +
>> + setup();
>> +
>> + for (lc = 0; TEST_LOOPING(lc); lc++) {
>> + Tst_count = 0; i = 0;
>> + ulast = 0, slast = 0;
>> + SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage);
>> + tst_resm(TINFO, "utime:%12luus; stime:%12luus",
>> + usage.ru_utime.tv_usec, usage.ru_stime.tv_usec);
>> + while (i < RECORD_MAX) {
>> + SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage);
>> + udelta = usage.ru_utime.tv_usec - ulast;
>> + sdelta = usage.ru_stime.tv_usec - slast;
>> + if (udelta > 0 || sdelta > 0) {
>> + i++;
>> + tst_resm(TINFO, "utime:%12luus; stime:%12luus",
>> + usage.ru_utime.tv_usec,
>> + usage.ru_stime.tv_usec);
>> + if (udelta > 1000+BIAS_MAX)
>> + tst_brkm(TFAIL, cleanup,
>> + "utime increased > 1000us:"
>> + " delta = %luus", udelta);
>> + if (sdelta > 1000+BIAS_MAX)
>> + tst_brkm(TFAIL, cleanup,
>> + "stime increased > 1000us:"
>> + " delta = %luus", sdelta);
>> + }
>> + ulast = usage.ru_utime.tv_usec;
>> + slast = usage.ru_stime.tv_usec;
>
> Hmm, you are actually looping the test for RECORD_MAX and then the whole
> test in test loop. Is there really need for that redundancy? Shouldn't
> be running the test with -i 20 sufficient?
-i 20 is not enough, the while-loop goes more than 20 times since there
is a condition:
+ if (udelta > 0 || sdelta > 0) {
+ i++;
only when both deltas > 0, the counter increases by 1.
>
>> + busyloop(100000);
>> + }
>> + }
>> + cleanup();
>> + tst_exit();
>> +}
>> +
>> +static void busyloop(int wait)
>> +{
>> + int i, j = 0;
>> +
>> + for (i = 0; i < wait; i++)
>> + j = j * 3 + 11;
>
> The j = j * 3 + 11 line would likely by removed by compiler
> optimalization.
>
> Also if you wan't to create bussy loop that loops for some microseconds
> you can use posix timers for that. Something like:
The loop is mainly for consuming some resources to increase CPU time, so
I removed j = j * 3 + 11 line, and use a while loop instead:
while (wait--)
;
>
>
> void sighandler(int sig)
> {
> signal_flag = 0;
> }
>
> void bussy_loop(void)
> {
> while (signal_flag);
> }
>
> ...
>
>
> timer_create()
>
> ...
>
> signal_flag = 1;
> timer_settime();
> bussy_loop();
>
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list