kernel mode to user mode switch

Hi,
how long does it takes to switch from kernel mode to user mode?

I’m currently using WinRT for my pcmcia driver and it is really slow. With
a scope I probe 9ms between the time the interrupt line goes down and my
first access to the card to serve the interrupt. The only bottleneck I can
think of is the switch from kernel mode to user mode. Is it possible that
it takes that long?

Thanks,
Michael

There is something else happening. The interrupt latencies I have timed
wsere in the order of 10s of microseconds, and that was on a 125 MHz Pentium
(not II or III or IV). Have you stepped throught he code and analyzed any
loop conditons? One good one would be is someone does a KeSetTimer call in a
criritcal path. That will incur a quantum (about 10 ms) delay.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105

wrote in message news:xxxxx@ntdev…
>
> Hi,
> how long does it takes to switch from kernel mode to user mode?
>
> I’m currently using WinRT for my pcmcia driver and it is really slow. With
> a scope I probe 9ms between the time the interrupt line goes down and my
> first access to the card to serve the interrupt. The only bottleneck I can
> think of is the switch from kernel mode to user mode. Is it possible that
> it takes that long?
>
> Thanks,
> Michael
>
>

I fix it, but I don’t know why…

Before, in the ISR, I just called the DPC and in the DPC, it signals a
thread to do the work. This thread check what cause the interrupt (I
have 8 causes), disable it, treat it and re-enable it. This doesn’t
work.

Now, in the ISR, I disable all the interrupts and call the DPC. The DPC
signals the thread. The thread, check what cause the interrupt, treat it
and re-enable all interrupts that has been disabled. This works, I got a
latency of 250us from the ISR to the thread.

Michael

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Thursday, January 23, 2003 12:03 PM
To: NT Developers Interest List
Subject: [ntdev] Re: kernel mode to user mode switch

There is something else happening. The interrupt latencies I have timed
wsere in the order of 10s of microseconds, and that was on a 125 MHz
Pentium (not II or III or IV). Have you stepped throught he code and
analyzed any loop conditons? One good one would be is someone does a
KeSetTimer call in a criritcal path. That will incur a quantum (about 10
ms) delay.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105

wrote in message news:xxxxx@ntdev…
>
> Hi,
> how long does it takes to switch from kernel mode to user mode?
>
> I’m currently using WinRT for my pcmcia driver and it is really slow.
> With a scope I probe 9ms between the time the interrupt line goes down

> and my first access to the card to serve the interrupt. The only
> bottleneck I can think of is the switch from kernel mode to user mode.

> Is it possible that it takes that long?
>
> Thanks,
> Michael
>
>


You are currently subscribed to ntdev as: xxxxx@maxt.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Did you disable ALL the interrupts of the PC or ALL interrupt-cases that
can cause an interrupt form your card ?

By the way, will your driver being used for real time IO and/or in live
critical
situations ( for example on airplaines ) ?

If you don’t like to do driver development ( as you suggested at the
" Numega DriverWorks or Jungo WinDriver? " forum item ), there are
a lot of people around here that would take over the job for you.

Christiaan

----- Original Message -----
From: “Michael Grimard”
To: “NT Developers Interest List”
Sent: Friday, January 24, 2003 3:38 PM
Subject: [ntdev] Re: kernel mode to user mode switch

> I fix it, but I don’t know why…
>
> Before, in the ISR, I just called the DPC and in the DPC, it signals a
> thread to do the work. This thread check what cause the interrupt (I
> have 8 causes), disable it, treat it and re-enable it. This doesn’t
> work.
>
> Now, in the ISR, I disable all the interrupts and call the DPC. The DPC
> signals the thread. The thread, check what cause the interrupt, treat it
> and re-enable all interrupts that has been disabled. This works, I got a
> latency of 250us from the ISR to the thread.
>
> Michael
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
> Sent: Thursday, January 23, 2003 12:03 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: kernel mode to user mode switch
>
>
> There is something else happening. The interrupt latencies I have timed
> wsere in the order of 10s of microseconds, and that was on a 125 MHz
> Pentium (not II or III or IV). Have you stepped throught he code and
> analyzed any loop conditons? One good one would be is someone does a
> KeSetTimer call in a criritcal path. That will incur a quantum (about 10
> ms) delay.
>
> –
> Gary G. Little
> Have Computer, Will Travel …
> 909-698-3191
> 909-551-2105
>
> wrote in message news:xxxxx@ntdev…
> >
> > Hi,
> > how long does it takes to switch from kernel mode to user mode?
> >
> > I’m currently using WinRT for my pcmcia driver and it is really slow.
> > With a scope I probe 9ms between the time the interrupt line goes down
>
> > and my first access to the card to serve the interrupt. The only
> > bottleneck I can think of is the switch from kernel mode to user mode.
>
> > Is it possible that it takes that long?
> >
> > Thanks,
> > Michael
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@maxt.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

>>Did you disable ALL the interrupts of the PC or ALL interrupt-cases
that can cause an interrupt form >>your card ?
I disabled the interrupt from the card.

>By the way, will your driver being used for real time IO and/or in
live critical situations ( for
>example on airplaines ) ?
No, only for test purposes.

>If you don’t like to do driver development ( as you suggested at the "
Numega DriverWorks or Jungo
>WinDriver? " forum item ), there are a lot of people around here that
would take over the job for
>you.
I started this thread…

Michael

----- Original Message -----
From: “Michael Grimard”
To: “NT Developers Interest List”
Sent: Friday, January 24, 2003 3:38 PM
Subject: [ntdev] Re: kernel mode to user mode switch

> I fix it, but I don’t know why…
>
> Before, in the ISR, I just called the DPC and in the DPC, it signals a

> thread to do the work. This thread check what cause the interrupt (I
> have 8 causes), disable it, treat it and re-enable it. This doesn’t
> work.
>
> Now, in the ISR, I disable all the interrupts and call the DPC. The
> DPC signals the thread. The thread, check what cause the interrupt,
> treat it and re-enable all interrupts that has been disabled. This
> works, I got a latency of 250us from the ISR to the thread.
>
> Michael
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
> Sent: Thursday, January 23, 2003 12:03 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: kernel mode to user mode switch
>
>
> There is something else happening. The interrupt latencies I have
> timed wsere in the order of 10s of microseconds, and that was on a 125

> MHz Pentium (not II or III or IV). Have you stepped throught he code
> and analyzed any loop conditons? One good one would be is someone does

> a KeSetTimer call in a criritcal path. That will incur a quantum
> (about 10
> ms) delay.
>
> –
> Gary G. Little
> Have Computer, Will Travel …
> 909-698-3191
> 909-551-2105
>
> wrote in message news:xxxxx@ntdev…
> >
> > Hi,
> > how long does it takes to switch from kernel mode to user mode?
> >
> > I’m currently using WinRT for my pcmcia driver and it is really
> > slow. With a scope I probe 9ms between the time the interrupt line
> > goes down
>
> > and my first access to the card to serve the interrupt. The only
> > bottleneck I can think of is the switch from kernel mode to user
> > mode.
>
> > Is it possible that it takes that long?
> >
> > Thanks,
> > Michael
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@maxt.com To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@maxt.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

You answered :

>>By the way, will your driver being used for real time IO and/or in
live critical situations ( for
>>example on airplaines ) ?
No, only for test purposes.

Ok, because statements as

> I fix it, but I don’t know why…

are not to be pronounced by driver developers. It may not
even come up in mind… At least, I have drilled myself to practice
this philosophy many years ago.

----- Original Message -----
From: “Michael Grimard”
To: “NT Developers Interest List”
Sent: Friday, January 24, 2003 5:34 PM
Subject: [ntdev] Re: kernel mode to user mode switch

> >>Did you disable ALL the interrupts of the PC or ALL interrupt-cases
> that can cause an interrupt form >>your card ?
> I disabled the interrupt from the card.
>
> >>By the way, will your driver being used for real time IO and/or in
> live critical situations ( for
> >>example on airplaines ) ?
> No, only for test purposes.
>
> >>If you don’t like to do driver development ( as you suggested at the "
> Numega DriverWorks or Jungo
> >>WinDriver? " forum item ), there are a lot of people around here that
> would take over the job for
> >>you.
> I started this thread…
>
>
> Michael
>
>
> ----- Original Message -----
> From: “Michael Grimard”
> To: “NT Developers Interest List”
> Sent: Friday, January 24, 2003 3:38 PM
> Subject: [ntdev] Re: kernel mode to user mode switch
>
>
> > I fix it, but I don’t know why…
> >
> > Before, in the ISR, I just called the DPC and in the DPC, it signals a
>
> > thread to do the work. This thread check what cause the interrupt (I
> > have 8 causes), disable it, treat it and re-enable it. This doesn’t
> > work.
> >
> > Now, in the ISR, I disable all the interrupts and call the DPC. The
> > DPC signals the thread. The thread, check what cause the interrupt,
> > treat it and re-enable all interrupts that has been disabled. This
> > works, I got a latency of 250us from the ISR to the thread.
> >
> > Michael
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
> > Sent: Thursday, January 23, 2003 12:03 PM
> > To: NT Developers Interest List
> > Subject: [ntdev] Re: kernel mode to user mode switch
> >
> >
> > There is something else happening. The interrupt latencies I have
> > timed wsere in the order of 10s of microseconds, and that was on a 125
>
> > MHz Pentium (not II or III or IV). Have you stepped throught he code
> > and analyzed any loop conditons? One good one would be is someone does
>
> > a KeSetTimer call in a criritcal path. That will incur a quantum
> > (about 10
> > ms) delay.
> >
> > –
> > Gary G. Little
> > Have Computer, Will Travel …
> > 909-698-3191
> > 909-551-2105
> >
> > wrote in message news:xxxxx@ntdev…
> > >
> > > Hi,
> > > how long does it takes to switch from kernel mode to user mode?
> > >
> > > I’m currently using WinRT for my pcmcia driver and it is really
> > > slow. With a scope I probe 9ms between the time the interrupt line
> > > goes down
> >
> > > and my first access to the card to serve the interrupt. The only
> > > bottleneck I can think of is the switch from kernel mode to user
> > > mode.
> >
> > > Is it possible that it takes that long?
> > >
> > > Thanks,
> > > Michael
> > >
> > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@maxt.com To
> > unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@maxt.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

A bit of a brute force way of doing things. You keep interrupts disable
until IRQL falls below DISPATCH_LEVEL so that your thread may run. Seems to
me that the better way would be to save the volatile states of the hardware
onto a queue, trigger the DPC and keep the interrupts enabled. The DPC, now
at DISPATCH_LEVEL, runs the queue looking for things to do and either
triggers the thread, or completes the action.

Your first attempt failed because you can only have one instance of a DPC
queued. Leaving the interrupts enabled allowed your ISR to run again once
you dropped below DIRQL which tried to queue another DPC. So … that ISR
was never seen by your DPC and never triggered the thread.

Like Christian said … some of us do it to make mortgage payments.


Gary G. Little
Have Computer, Will Travel …
909-698-3191
909-551-2105

“Michael Grimard” wrote in message news:xxxxx@ntdev…
>
> I fix it, but I don’t know why…
>
> Before, in the ISR, I just called the DPC and in the DPC, it signals a
> thread to do the work. This thread check what cause the interrupt (I
> have 8 causes), disable it, treat it and re-enable it. This doesn’t
> work.
>
> Now, in the ISR, I disable all the interrupts and call the DPC. The DPC
> signals the thread. The thread, check what cause the interrupt, treat it
> and re-enable all interrupts that has been disabled. This works, I got a
> latency of 250us from the ISR to the thread.
>
> Michael
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
> Sent: Thursday, January 23, 2003 12:03 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: kernel mode to user mode switch
>
>
> There is something else happening. The interrupt latencies I have timed
> wsere in the order of 10s of microseconds, and that was on a 125 MHz
> Pentium (not II or III or IV). Have you stepped throught he code and
> analyzed any loop conditons? One good one would be is someone does a
> KeSetTimer call in a criritcal path. That will incur a quantum (about 10
> ms) delay.
>
> –
> Gary G. Little
> Have Computer, Will Travel …
> 909-698-3191
> 909-551-2105
>
> wrote in message news:xxxxx@ntdev…
> >
> > Hi,
> > how long does it takes to switch from kernel mode to user mode?
> >
> > I’m currently using WinRT for my pcmcia driver and it is really slow.
> > With a scope I probe 9ms between the time the interrupt line goes down
>
> > and my first access to the card to serve the interrupt. The only
> > bottleneck I can think of is the switch from kernel mode to user mode.
>
> > Is it possible that it takes that long?
> >
> > Thanks,
> > Michael
> >
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@maxt.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>

> and re-enable all interrupts that has been disabled. This works, I
got a

latency of 250us from the ISR to the thread.

How loaded your system is? On a heavily loaded system - especially
with IDE CD drive in PIO mode - you will have significantly large
figures.

IMHO the main task is to take the data off the device to the host
memory ASAP. Relying on user thread to do this looks bad, it is much
better to do this in the DPC itself. The latter way requires the user
app to send the overlapped reads to the driver, in order for it to
have the buffer space to take the data to.

Audio/video support in WDM OSes work this way, including, for
instance, the 1394 stuff.

Max