2005-04-09 05:02:45

by philip dahlquist

[permalink] [raw]
Subject: easy softball jiffies quest(ion)

hi,

i'm on a quest to get access to jiffies in user space so i can write a
simple stepper motor driver program. i co-opted the "#includes" list
from alessandro rubini's jit.c file from "linux device drivers" to write
jfi.c.

this is it:
------------------------------------------------------------------
#include <linux/config.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>

#include <linux/time.h>
#include <linux/timer.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>

#include <asm/hardirq.h>


int main(void)
{
unsigned long j = jiffies + (50 * HZ);
printf("start jiffies = %9li\n",jiffies);
while(jiffies < j)
;

printf("done jiffies = %9li\n", jiffies);
return 0;
}

-----------------------------------------------------------
all right, you can giggle, but no laughing out loud, my kernel ego is
nacent and fragile.

when i compile it with:

gcc -o jfi.x jfi.c

i get a handful of errors regarding various #include statements:
-------------------------------------------------
jfi.c:3:31: linux/moduleparam.h: No such file or directory
In file included from jfi.c:6:
/usr/include/linux/time.h:10: error: syntax error before "time_t"
/usr/include/linux/time.h:12: error: syntax error before '}' token
/usr/include/linux/time.h:18: error: syntax error before "time_t"
/usr/include/linux/time.h:44: error: field `it_interval' has incomplete type
/usr/include/linux/time.h:45: error: field `it_value' has incomplete type
/usr/include/linux/time.h:49: error: field `it_interval' has incomplete type
/usr/include/linux/time.h:50: error: field `it_value' has incomplete type
jfi.c:7:25: linux/timer.h: No such file or directory
In file included from /usr/include/linux/interrupt.h:9,
from jfi.c:12:
/usr/include/asm/bitops.h:327:2: warning: #warning This include file is
not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers
in userspace: atomicity not guaranteed
In file included from jfi.c:12:
/usr/include/linux/interrupt.h:12:25: asm/hardirq.h: No such file or directory
/usr/include/linux/interrupt.h:13:25: asm/softirq.h: No such file or directory

jfi.c: In function `main':
jfi.c:19: error: `jiffies' undeclared (first use in this function)
jfi.c:19: error: (Each undeclared identifier is reported only once
jfi.c:19: error: for each function it appears in.)
./jfsh: line 8: jfi.x: command not found
---------------------------------------------------------------------

i kind of figured you guys would know what to do. it's sort of a rarefied
group. anyway, if you can help, i'd really appreciate it, because
alessandro's makefile was somewhat cryptic.


you know, the operating systems class this semester at the university
of maryland, college park, was taught based on that new, exciting os, win xp.
and he managed to turn a 2 day class, where a day has a lecture and a lab,
into a 4 day affair, monday lecture, tuesday lab, wednesday lecture, thursday
lab. i took data structures instead. i am not taking any win xp os
class. it's linux or nothing. can you believe that, win xp?

one more thing, um, i'm paralyzed from the shoulders down, but i can type
with both hands using typing aids, and i also use a kensington "expert mouse"
trackball. i would like to write a mouse manager where i could assign
different actions for each button, something very similar to the kensington
interface that's available for, um, windows. i found some xwindow functions
for button pressing events, but i don't know how to get into the mouse driver
or button events in xwindows or gnome, etc.

if somebody has a direction to go for that, that would be a big help.

thanks, or tgfl(inux),
philip dahlquist


2005-04-09 05:51:16

by Vadim Lobanov

[permalink] [raw]
Subject: Re: easy softball jiffies quest(ion)

On Sat, 9 Apr 2005, philip dahlquist wrote:

> hi,

Hello,

> i'm on a quest to get access to jiffies in user space so i can write a
> simple stepper motor driver program. i co-opted the "#includes" list
> from alessandro rubini's jit.c file from "linux device drivers" to write
> jfi.c.

Now, I might be _entirely_ off-base here, but... from what I know (which
is, admittedly, less than what many others here do) jiffies are a
kernel-land concept, implemented using a kernel-land variable. The
kernel protects itself from user-land programs, so your user-land
program will never be able to access the jiffies variable directly like
that.

As far as I know, it breaks down like this: If you want jiffies, then
your code should be a kernel module. If you want your code to run in
user-land, then you have to settle for knowing the time using alarm(),
clock_gettime(), gettimeofday(), or similar system-call-based mechanism.

> this is it:
> ------------------------------------------------------------------
> #include <linux/config.h>
> #include <linux/module.h>
> #include <linux/moduleparam.h>
> #include <linux/init.h>
>
> #include <linux/time.h>
> #include <linux/timer.h>
> #include <linux/kernel.h>
> #include <linux/proc_fs.h>
> #include <linux/types.h>
> #include <linux/spinlock.h>
> #include <linux/interrupt.h>
>
> #include <asm/hardirq.h>
>
>
> int main(void)
> {
> unsigned long j = jiffies + (50 * HZ);
> printf("start jiffies = %9li\n",jiffies);
> while(jiffies < j)
> ;
>
> printf("done jiffies = %9li\n", jiffies);
> return 0;
> }
>
> -----------------------------------------------------------
> all right, you can giggle, but no laughing out loud, my kernel ego is
> nacent and fragile.
>
> when i compile it with:
>
> gcc -o jfi.x jfi.c
>
> i get a handful of errors regarding various #include statements:
> -------------------------------------------------
> jfi.c:3:31: linux/moduleparam.h: No such file or directory
> In file included from jfi.c:6:
> /usr/include/linux/time.h:10: error: syntax error before "time_t"
> /usr/include/linux/time.h:12: error: syntax error before '}' token
> /usr/include/linux/time.h:18: error: syntax error before "time_t"
> /usr/include/linux/time.h:44: error: field `it_interval' has incomplete type
> /usr/include/linux/time.h:45: error: field `it_value' has incomplete type
> /usr/include/linux/time.h:49: error: field `it_interval' has incomplete type
> /usr/include/linux/time.h:50: error: field `it_value' has incomplete type
> jfi.c:7:25: linux/timer.h: No such file or directory
> In file included from /usr/include/linux/interrupt.h:9,
> from jfi.c:12:
> /usr/include/asm/bitops.h:327:2: warning: #warning This include file is
> not available on all architectures.
> /usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers
> in userspace: atomicity not guaranteed
> In file included from jfi.c:12:
> /usr/include/linux/interrupt.h:12:25: asm/hardirq.h: No such file or directory
> /usr/include/linux/interrupt.h:13:25: asm/softirq.h: No such file or directory
>
> jfi.c: In function `main':
> jfi.c:19: error: `jiffies' undeclared (first use in this function)
> jfi.c:19: error: (Each undeclared identifier is reported only once
> jfi.c:19: error: for each function it appears in.)
> ./jfsh: line 8: jfi.x: command not found
> ---------------------------------------------------------------------

All the above errors come from the fact that you're trying to use
kernel-land include files and definitions within a user-program.
Probably not doable.

> i kind of figured you guys would know what to do. it's sort of a rarefied
> group. anyway, if you can help, i'd really appreciate it, because
> alessandro's makefile was somewhat cryptic.
>
>
> you know, the operating systems class this semester at the university
> of maryland, college park, was taught based on that new, exciting os, win xp.
> and he managed to turn a 2 day class, where a day has a lecture and a lab,
> into a 4 day affair, monday lecture, tuesday lab, wednesday lecture, thursday
> lab. i took data structures instead. i am not taking any win xp os
> class. it's linux or nothing. can you believe that, win xp?

(Keep in mind that the following is my opinion only.) I'd say that
taking a Windows class might still be educational. Operating systems are
such a thing where learning one helps you understand a great deal about
_all_ of them. If anything, it'll at least give you more educated
reasons for disliking / hating our "favorite" monopolistic company or
operating system. :-)

> one more thing, um, i'm paralyzed from the shoulders down, but i can type
> with both hands using typing aids, and i also use a kensington "expert mouse"
> trackball. i would like to write a mouse manager where i could assign
> different actions for each button, something very similar to the kensington
> interface that's available for, um, windows. i found some xwindow functions
> for button pressing events, but i don't know how to get into the mouse driver
> or button events in xwindows or gnome, etc.

Depends upon what functionality you want to have those buttons to have.
If it's nothing super fancy, it might very well be doable in user-space
without having to muck around inside the kernel. A combination of
xmodmap and configuration files, maybe? (Not an expert on this, I'm
afraid to say.)

> if somebody has a direction to go for that, that would be a big help.
>
> thanks, or tgfl(inux),
> philip dahlquist

Vadim Lobanov.

> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2005-04-11 02:39:35

by Robert Hancock

[permalink] [raw]
Subject: Re: easy softball jiffies quest(ion)

philip dahlquist wrote:
> hi,
>
> i'm on a quest to get access to jiffies in user space so i can write a
> simple stepper motor driver program. i co-opted the "#includes" list
> from alessandro rubini's jit.c file from "linux device drivers" to write
> jfi.c.

That's not going to work, jiffies is an internal kernel value, you can't
access it from userspace. What do you need jiffies for to do this?

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/


2005-04-20 03:36:29

by James Cleverdon

[permalink] [raw]
Subject: Re: easy softball jiffies quest(ion)

As others have said, maybe jiffies isn't the time value you want.
However, clock ticks are available in userland via the times system
call.

Note the warning at the end; you'll have to do your comparisons
correctly or fail when the counter overflows.

man 2 times:

...
Return Value
The function times returns the number of clock ticks that have
elapsed since an arbitrary point in the past. For Linux this
point is the moment the system was booted. This return
value may overflow the possible range of type clock_t.


On Friday 08 April 2005 10:02 pm, philip dahlquist wrote:
> hi,
>
> i'm on a quest to get access to jiffies in user space so i can write
> a simple stepper motor driver program. i co-opted the "#includes"
> list from alessandro rubini's jit.c file from "linux device drivers"
> to write jfi.c.
>
> this is it:
> ------------------------------------------------------------------
> #include <linux/config.h>
> #include <linux/module.h>
> #include <linux/moduleparam.h>
> #include <linux/init.h>
>
> #include <linux/time.h>
> #include <linux/timer.h>
> #include <linux/kernel.h>
> #include <linux/proc_fs.h>
> #include <linux/types.h>
> #include <linux/spinlock.h>
> #include <linux/interrupt.h>
>
> #include <asm/hardirq.h>
>
>
> int main(void)
> {
> unsigned long j = jiffies + (50 * HZ);
> printf("start jiffies = %9li\n",jiffies);
> while(jiffies < j)
> ;
>
> printf("done jiffies = %9li\n", jiffies);
> return 0;
> }
[[ Snip! ]]

--
James Cleverdon
IBM LTC (xSeries Linux Solutions)
{jamesclv(Unix, preferred), cleverdj(Notes)} at us dot ibm dot comm