Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 2000 12:38:25 +0930
From:      Greg Lehey <grog@lemis.com>
To:        FreeBSD-smp@FreeBSD.org
Subject:   Interrupt threads: implementation questions
Message-ID:  <20000720123824.M50320@wantadilla.lemis.com>

index | next in thread | raw e-mail

I'm currently working my way through the creation of interrupt
processes or threads, and I find that it's a lot more complicated than
I thought.  The BSD/OS implementation of processes is now so different
from ours that porting is quite complicated.  At the moment I'm
looking at how the process context is allocated.  BSD/OS just does

	/* Allocate new proc. */
	psz = sizeof(struct proc);
	if ((SCARG(uap, runflags) & SF_KTHREAD)) {
		if (suser(p1->p_cred->pc_ucred, NULL) == EPERM)
			SCARG(uap, runflags) &= ~SF_KTHREAD;
		else {
			/* kernel threads define their proc size */
			psz = SCARG(uap, runflags) >> SF_SZSHIFT;
		}
	}
	MALLOC(newproc, struct proc *, psz, M_PROC, M_WAITOK);

The reason for this code is that the "struct proc" for kernel threads
(in this case, interrupt threads) is really a struct ithd, which
contains a struct proc and a few additional fields.

In FreeBSD, we allocate the struct proc in fork1() with

	/* Allocate new proc. */
	newproc = zalloc(proc_zone);

proc_zone is of type vm_zone_t, and contains additional information.
If I read the code correctly, I should be able to define another zone
variable, ithread_zone, and then change the code above to

	/* Allocate new proc. */
	if (flags & RFITHREAD)
		newproc = zalloc(ithread_zone);
	else
		newproc = zalloc(proc_zone);

Am I missing anything?  One thing might be that other kernel threads
(non-interrupt) might use a different structure again, though it would
be nice to be able to keep them consistent.  Or should I just add
fields to struct proc?  There aren't many additional fields in struct
ithd: here's the entire definition from BSD/OS:

/*
 * Interrupt thread (based on a proc)
 */
struct ithd {
	struct proc it_proc;
	int it_need;			/* Needs service */
	int it_runstat;			/* Run lock */
	struct	intrhand *it_ih;	/* head of handler queue */
/*	struct ithd *it_interrupted;	/* Who we interrupted */
	/* stats -- (none yet) */
};

My feeling is that this is enough bloat not to add it to every
process, especially when we decide to add the statistics.  A better
alternative might be to have a pointer to these data in the struct
proc, possibly reusing a field which has no meaning in kernel thread
context.  We could then leave fork1() effectively as it is.

BTW, don't get too upset about the term "interrupt thread".  As
agreed, I'm currently implementing the heavyweight interrupt
processes, but the real difference isn't in the allocation, it's in
the scheduling.

Greg
--
Finger grog@lemis.com for PGP public key
See complete headers for address and phone numbers


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message



help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000720123824.M50320>