2005-09-28 22:02:56

by Bhattacharjee, Satadal

[permalink] [raw]
Subject: Registering for multiple SIGIO within a process

Hi,
I have hit a typical situation where I am having issues with signals. Below
is the description of the issue.
There are two separate Host Bus Adapters (HBA) connected to the system. Each
HBA has its own driver loaded in the kernel.

There are two separate shared objects to talk to each of the drivers. One
shared object does not communicate with the other one.

Each shared object has function within it to register with kernel to receive
SIGIO when an event is generated by the HBA. Driver received the event from
the HBA and sends SIGIO to the kernel.

There is an application (executable) which loads the two shared objects.
Application then calls function within the shared object to register events
from HBA.

When driver generates a signal, the shared object which registered last,
receives the signal. The first registration never receives any signal.

Now I checked the man pages and found out that you can register for the same
signal only once from a process.
We tried to change the signal from SIGIO to SIGUSER1 in one of the shared
object. But on checking the kernel code we realized that only SIGIO is
supported.

So can somebody suggest what is the correct mechanism to register with the
kernel for receiving multiple signals from a single process?

I am not subscribed to the list, so please copy me in the CC field when
replying.
The shared object code snippet for registration is below:
struct sigaction sa;
int oflags;
int rc = 0;
// setup the signal handler
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = &AENSignalHandler; // AENSignalHandler is the signal handler

//sa.sa_flags = SA_ONESHOT;
sigfillset(&sa.sa_mask);
sigaction(SIGIO, &sa, NULL);
//aen_do_registration - enable driver to send us SIGIO for event
notification
rc = fcntl(ghMegaDev, F_SETOWN, getpid()); // ghMegaDev is the handle to the
driver
if (rc < 0) {
perror("AEN: registration, F_SETOWN");
return SL_ERR_LINUX_AEN_INIT_FAILED;
}
oflags = fcntl(ghMegaDev, F_GETFL);
rc = fcntl(ghMegaDev, F_SETFL, oflags| FASYNC);
if (rc < 0) {
perror("setup_aen_handler: Failed to set ASYNC flag\n");
return SL_ERR_LINUX_AEN_INIT_FAILED;
}
*****************************************************************
Satadal Bhattacharjee,
LSI Logic Corp.,
3098 W Warren Ave,
Fremont, CA, 94539
[email protected]
(408) 433-4204


2005-09-28 22:51:49

by Ray Lee

[permalink] [raw]
Subject: Re: Registering for multiple SIGIO within a process

On 9/28/05, Bhattacharjee, Satadal <[email protected]> wrote:
[...]
> Each shared object has function within it to register with kernel to receive
> SIGIO when an event is generated by the HBA. Driver received the event from
> the HBA and sends SIGIO to the kernel.
[...]
> When driver generates a signal, the shared object which registered last,
> receives the signal. The first registration never receives any signal.
[...]
> So can somebody suggest what is the correct mechanism to register with the
> kernel for receiving multiple signals from a single process?

(Sheesh, what is it with people thinking signals are something to be
used in any design after the 1970's?)

You're out of luck. Either register a sigio handler as a dispatcher in
your loader (shell) process before either of the two shared objects
do, and then somehow echo the signal to the correct object by hand
(assuming you can determine which HBA raised the signal -- and no idea
how'd you do this, actually), or fork() the main shell process into at
least one other one to allow receiving of the signals separately. I'd
suggest fork()ing twice, once per HBA, as that'd probably end up
simpler code-wise.

Ray

2005-09-28 23:08:59

by Bharath Ramesh

[permalink] [raw]
Subject: Re: Registering for multiple SIGIO within a process

I am not sure if this would work but you could try registering
different real time signals to be delivered to the shared object
instead of SIGIO. I am not sure if it would work. I do use RT signals
to be used instead of SIGIO.

You could try probably something like this

fcntl (devhandle, SETOWN, getpid ());
fcntl (devhandle, SETSIG, SIGRTMIN);
fcntl (devhandle, SETFL, O_ASYNC);

try registering a signal handler for SIGRTMIN like SIGIO. Could be a
possible solution.

Bharath

On 9/28/05, Bhattacharjee, Satadal <[email protected]> wrote:
> Hi,
> I have hit a typical situation where I am having issues with signals. Below
> is the description of the issue.
> There are two separate Host Bus Adapters (HBA) connected to the system. Each
> HBA has its own driver loaded in the kernel.
>
> There are two separate shared objects to talk to each of the drivers. One
> shared object does not communicate with the other one.
>
> Each shared object has function within it to register with kernel to receive
> SIGIO when an event is generated by the HBA. Driver received the event from
> the HBA and sends SIGIO to the kernel.
>
> There is an application (executable) which loads the two shared objects.
> Application then calls function within the shared object to register events
> from HBA.
>
> When driver generates a signal, the shared object which registered last,
> receives the signal. The first registration never receives any signal.
>
> Now I checked the man pages and found out that you can register for the same
> signal only once from a process.
> We tried to change the signal from SIGIO to SIGUSER1 in one of the shared
> object. But on checking the kernel code we realized that only SIGIO is
> supported.
>
> So can somebody suggest what is the correct mechanism to register with the
> kernel for receiving multiple signals from a single process?
>
> I am not subscribed to the list, so please copy me in the CC field when
> replying.
> The shared object code snippet for registration is below:
> struct sigaction sa;
> int oflags;
> int rc = 0;
> // setup the signal handler
> memset(&sa, 0, sizeof(struct sigaction));
> sa.sa_handler = &AENSignalHandler; // AENSignalHandler is the signal handler
>
> //sa.sa_flags = SA_ONESHOT;
> sigfillset(&sa.sa_mask);
> sigaction(SIGIO, &sa, NULL);
> //aen_do_registration - enable driver to send us SIGIO for event
> notification
> rc = fcntl(ghMegaDev, F_SETOWN, getpid()); // ghMegaDev is the handle to the
> driver
> if (rc < 0) {
> perror("AEN: registration, F_SETOWN");
> return SL_ERR_LINUX_AEN_INIT_FAILED;
> }
> oflags = fcntl(ghMegaDev, F_GETFL);
> rc = fcntl(ghMegaDev, F_SETFL, oflags| FASYNC);
> if (rc < 0) {
> perror("setup_aen_handler: Failed to set ASYNC flag\n");
> return SL_ERR_LINUX_AEN_INIT_FAILED;
> }
> *****************************************************************
> Satadal Bhattacharjee,
> LSI Logic Corp.,
> 3098 W Warren Ave,
> Fremont, CA, 94539
> [email protected]
> (408) 433-4204
>
> -
> 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-09-29 00:45:14

by Bagalkote, Sreenivas

[permalink] [raw]
Subject: RE: Registering for multiple SIGIO within a process

>
>(Sheesh, what is it with people thinking signals are something
>to be used in any design after the 1970's?)
>

What's your recommendation for asynchronous notification from driver
to an application?

2005-09-29 01:15:58

by Ray Lee

[permalink] [raw]
Subject: RE: Registering for multiple SIGIO within a process

On Wed, 2005-09-28 at 20:44 -0400, Bagalkote, Sreenivas wrote:
> >(Sheesh, what is it with people thinking signals are something
> >to be used in any design after the 1970's?)
> What's your recommendation for asynchronous notification from driver
> to an application?

Pass back an fd to select() upon. Cuts out that nasty middle step where
app authors end up registering a signal handler that merely write()s the
signal number down a pipe into the (nearly ubiquitous) select loop.

Ray

2005-09-29 03:50:14

by Bharath Ramesh

[permalink] [raw]
Subject: Re: Registering for multiple SIGIO within a process

On 9/28/05, Ray Lee <[email protected]> wrote:
> On Wed, 2005-09-28 at 20:44 -0400, Bagalkote, Sreenivas wrote:
> > >(Sheesh, what is it with people thinking signals are something
> > >to be used in any design after the 1970's?)
> > What's your recommendation for asynchronous notification from driver
> > to an application?
>
> Pass back an fd to select() upon. Cuts out that nasty middle step where
> app authors end up registering a signal handler that merely write()s the
> signal number down a pipe into the (nearly ubiquitous) select loop.

If its just linux i would use asynchronous notification using RT
signals. You can use sigwaitinfo to check for the arrival of the
signal by blocking it. siginfo will contain the fd which receivd the
notification. That saves you the call to select as you would have to
select upto maxfd. If you are using just one fd poll would be a better
option IMHO.


Bharath

2005-09-29 04:09:19

by Bagalkote, Sreenivas

[permalink] [raw]
Subject: RE: Registering for multiple SIGIO within a process

>
>On Wed, 2005-09-28 at 20:44 -0400, Bagalkote, Sreenivas wrote:
>> >(Sheesh, what is it with people thinking signals are
>something to be
>> >used in any design after the 1970's?)
>> What's your recommendation for asynchronous notification from driver
>> to an application?
>
>Pass back an fd to select() upon. Cuts out that nasty middle
>step where app authors end up registering a signal handler
>that merely write()s the signal number down a pipe into the
>(nearly ubiquitous) select loop.
>
>Ray
>

select() is not asynchronous to the app (like a signal handler is).

2005-09-29 05:28:14

by Ray Lee

[permalink] [raw]
Subject: RE: Registering for multiple SIGIO within a process

On Thu, 2005-09-29 at 00:09 -0400, Bagalkote, Sreenivas wrote:
> select() is not asynchronous to the app (like a signal handler is).

(Way off topic now, but...)

Correct. Asynchronous to the app is rarely what an app author wants,
though (at least this app author). Asynchronous is the unix version of
throwing an exception in OO languages, which is fine for something
that's exceptional. As for something that one *expects* as a matter of
course (a broken pipe or SIGXFSZ upon a write(), for example), having a
signal arrive out of line from normal processing is a pain, and
needlessly complicates code.

Further, if you took a poll of random self-proclaimed Unix/C hackers, I
bet fewer than 1 in 10 could actually tell you what functions are *safe*
to call inside the handler. (Probably less than half even realize
there's a problem. Better, I bet a large percentage of them don't even
understand the case that they can be introducing race conditions with
signal handlers.)

The common, safe, approach taken by those who do realize that there's an
issue is to just collect the signals as they arrive, and merely perform
a write to transfer it into the main select loop (which, seemingly, most
programs have). The main select() loop then deals with the signals as
events rather than exceptions.

As I mentioned up top, this is straying far off course, and into my
personal software practices. As I'm just some random guy, I'd suggest
ignoring me :-).

For the matter mentioned at top of the email thread, forking a couple
separate processes communicating back to the parent should take care of
the issue of wanting to register for the same signal twice under two
different contexts.

Ray