[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.64.0708241442590.28540@fbirervta.pbzchgretzou.qr>
Date: Fri, 24 Aug 2007 14:46:52 +0200 (CEST)
From: Jan Engelhardt <jengelh@...putergmbh.de>
To: "linux-os (Dick Johnson)" <linux-os@...logic.com>
cc: Luka Napotnik <luka.napotnik@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: division and cpu usage
On Aug 24 2007 07:34, linux-os (Dick Johnson) wrote:
>> I'm new to kernel development and have some questions.
>>
>> 1. Why can't I divide with regular casting to double ((double)a /
>> (double)b)? It gives me strange errors when compiling:
>>
>> WARNING: "__divdf3" [/root....] undefined!
>> WARNING: "__addf3" [/root/...] undefined!
>> WARNING: "__floatsidf" [/root/...] undefined!
>>
>> And if I compile with normal integers, I get zero as the result.
>>
>> 2. I'm trying to get the percentage of CPU used for a certain
>> task_struct and figured the following formula:
>>
>> (task->utime + task->stime) / jiffies
>>
>> Before calculating I convert all the variables to jiffies. Is this correct?
* So use integer math: (task->utime + task->stime) * 100 / jiffies
and you get the 'common' percentage. In integer, that is.
* I am not sure about the use of jiffies when it comes to CONFIG_NO_HZ=y.
>Floating point operations are not allowed in the kernel. Often,
IIRC they are allowed since ... recently (2.6.16, .17? can't remember). When
the kernel tries to execute an FP instruction (and traps as a result), more
kernel code will enable that the FP stack gets properly switched when a process
changes between userspace-kernelspace.
>You can use "long long" for high precision math if necessary.
That will give link failure for __udivdi3. Use do_div().
Jan
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists