kqueue single test working

This commit is contained in:
BuildTools 2019-02-20 01:49:23 -05:00
parent 4799962a7d
commit b5694adbe7
6 changed files with 960 additions and 218 deletions

File diff suppressed because it is too large Load Diff

View File

@ -690,7 +690,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *
/*
* Tell any interested parties about the new process.
*/
knote_fork(p1->p_klist, p2->p_pid);
knote_fork(p1->p_klist, td, p2->p_pid);
/*
* Now can be swapped.

View File

@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <sys/umtx.h>
#include <sys/vmmeter.h>
#include <sys/cpuset.h>
#include <sys/event.h>
#ifdef HWPMC_HOOKS
#include <sys/pmckern.h>
#endif
@ -444,6 +445,9 @@ thread_free(struct thread *td)
cpu_thread_free(td);
if (td->td_kstack != 0)
vm_thread_dispose(td);
if (td->td_kevq_thred != NULL) {
kevq_thred_drain(td->td_kevq_thred);
}
callout_drain(&td->td_slpcallout);
uma_zfree(thread_zone, td);
}

View File

@ -33,6 +33,8 @@
#include <sys/_types.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#define EVFILT_READ (-1)
#define EVFILT_WRITE (-2)
@ -143,6 +145,10 @@ struct kevent32_freebsd11 {
#define EV_CLEAR 0x0020 /* clear event state after reporting */
#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */
#define EV_DISPATCH 0x0080 /* disable event after reporting */
#define EV_MULTI 0x0200 /* enable multithreaded mode, only works for the first kevent passed in
* This flag of subsequent kevents is ignored
*/
#define EV_AFFINITY 0x0400 /* in multithreaded mode, this event has hard affinity for the registering thread */
#define EV_SYSFLAGS 0xF000 /* reserved by system */
#define EV_DROP 0x1000 /* note should be dropped */
@ -220,6 +226,9 @@ struct knote;
SLIST_HEAD(klist, knote);
struct kqueue;
TAILQ_HEAD(kqlist, kqueue);
struct kevq;
SLIST_HEAD(kevqlist, kevq);
struct knlist {
struct klist kl_list;
void (*kl_lock)(void *); /* lock function */
@ -269,6 +278,10 @@ struct filterops {
void (*f_touch)(struct knote *kn, struct kevent *kev, u_long type);
};
/* The ioctl to set multithreaded mode
*/
#define FKQMULTI _IOW('f', 89, int)
/*
* An in-flux knote cannot be dropped from its kq while the kq is
* unlocked. If the KN_SCAN flag is not set, a thread can only set
@ -283,7 +296,9 @@ struct knote {
SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */
struct knlist *kn_knlist; /* f_attach populated */
TAILQ_ENTRY(knote) kn_tqe;
struct kqueue *kn_kq; /* which queue we are on */
struct kqueue *kn_kq; /* which kqueue we are on */
struct kevq *kn_org_kevq; /* the kevq that registered the knote */
struct kevq *kn_kevq; /* the kevq the knote is on */
struct kevent kn_kevent;
void *kn_hook;
int kn_hookid;
@ -295,7 +310,9 @@ struct knote {
#define KN_MARKER 0x20 /* ignore this knote */
#define KN_KQUEUE 0x40 /* this knote belongs to a kq */
#define KN_SCAN 0x100 /* flux set in kqueue_scan() */
int kn_fluxwait;
int kn_influx;
struct mtx kn_fluxlock;
int kn_sfflags; /* saved filter flags */
int64_t kn_sdata; /* saved data field */
union {
@ -321,6 +338,14 @@ struct kevent_copyops {
size_t kevent_size;
};
struct kevq_thred {
u_long kevq_hashmask; /* hash mask for kevqs */
struct kevqlist *kevq_hash; /* hash table for kevqs */
TAILQ_HEAD(, kevq) kevq_tq;
struct mtx lock; /* the lock for the kevq*/
};
struct thread;
struct proc;
struct knlist;
@ -328,7 +353,7 @@ struct mtx;
struct rwlock;
void knote(struct knlist *list, long hint, int lockflags);
void knote_fork(struct knlist *list, int pid);
void knote_fork(struct knlist *list, struct thread *td, int pid);
struct knlist *knlist_alloc(struct mtx *lock);
void knlist_detach(struct knlist *knl);
void knlist_add(struct knlist *knl, struct knote *kn, int islocked);
@ -352,6 +377,7 @@ int kqfd_register(int fd, struct kevent *kev, struct thread *p,
int kqueue_add_filteropts(int filt, struct filterops *filtops);
int kqueue_del_filteropts(int filt);
void kevq_thred_drain(struct kevq_thred *kevq_th);
#else /* !_KERNEL */
#include <sys/cdefs.h>

View File

@ -40,27 +40,46 @@
#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */
#define KQEXTENT 256 /* linear growth by this amount */
struct kevq {
SLIST_ENTRY(kevq) kevq_th_e; /* entry into kevq_thred's hashtable */
TAILQ_ENTRY(kevq) kq_e; /* entry into kqueue's list */
TAILQ_ENTRY(kevq) kevq_th_tqe; /* entry into kevq_thred's TAILQ */
struct kqueue *kq; /* the kq that the kevq belongs to */
struct kevq_thred *kevq_th; /* the thread that the kevq belongs to */
struct mtx lock; /* the lock for the kevq */
TAILQ_HEAD(, knote) kn_head; /* list of pending knotes */
int kn_count; /* number of pending knotes */
#define KEVQ_SLEEP 0x01
#define KEVQ_CLOSING 0x02
int kevq_state;
int kevq_refcnt;
};
struct kqueue {
struct mtx kq_lock;
int kq_refcnt;
TAILQ_ENTRY(kqueue) kq_list;
TAILQ_HEAD(, knote) kq_head; /* list of pending event */
int kq_count; /* number of pending events */
struct selinfo kq_sel;
struct sigio *kq_sigio;
struct filedesc *kq_fdp;
int kq_state;
#define KQ_SEL 0x01
#define KQ_SLEEP 0x02
#define KQ_FLUXWAIT 0x04 /* waiting for a in flux kn */
#define KQ_ASYNC 0x08
#define KQ_ASYNC 0x02
#define KQ_TASKSCHED 0x04 /* task scheduled */
#define KQ_TASKDRAIN 0x08 /* waiting for task to drain */
#define KQ_CLOSING 0x10
#define KQ_TASKSCHED 0x20 /* task scheduled */
#define KQ_TASKDRAIN 0x40 /* waiting for task to drain */
#define KQ_FLAG_INIT 0x20 /* kqueue has been initialized. this flag is set after the first kevent structure is processed */
#define KQ_FLAG_MULTI 0x40 /* Multi-threaded mode */
TAILQ_ENTRY(kqueue) kq_list;
struct sigio *kq_sigio;
struct filedesc *kq_fdp;
int kq_knlistsize; /* size of knlist */
struct klist *kq_knlist; /* list of knotes */
u_long kq_knhashmask; /* size of knhash */
struct klist *kq_knhash; /* hash table for knotes */
/* only-set: in multithreaded mode */
TAILQ_HEAD(, kevq) kq_kevqlist; /* list of kevqs interested in the kqueue */
struct kevq *kq_ckevq; /* current kevq for multithreaded kqueue */
/* only-set: in single threaded mode */
struct kevq *kq_kevq;
/* End only-set */
struct task kq_task;
struct ucred *kq_cred;
};

View File

@ -365,6 +365,7 @@ struct thread {
void *td_lkpi_task; /* LinuxKPI task struct pointer */
struct epoch_tracker *td_et; /* (k) compat KPI spare tracker */
int td_pmcpend;
struct kevq_thred *td_kevq_thred;
};
struct thread0_storage {