Page MenuHomeFreeBSD

File Metadata

Author
ae
Created
Apr 20 2019, 8:57 AM
/*-
* Copyright (c) 2019 Andrey V. Elsukov <ae@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/epoch.h>
extern epoch_t net_epoch_preempt;
struct test {
uint64_t data;
struct epoch_context epoch_ctx;
};
static void
deferred_free(epoch_context_t ctx)
{
struct test *p;
p = __containerof(ctx, struct test, epoch_ctx);
free(p, M_TEMP);
}
static int
modevent(module_t mod, int type, void *unused)
{
struct test *p;
switch (type) {
case MOD_LOAD:
break;
case MOD_UNLOAD:
p = malloc(sizeof(*p), M_TEMP, M_WAITOK | M_ZERO);
epoch_call(net_epoch_preempt, &p->epoch_ctx, deferred_free);
//epoch_call_drain(net_epoch_preempt);
break;
default:
return (EOPNOTSUPP);
}
return (0);
}
static moduledata_t mod = {
"epoch_test",
modevent,
0
};
DECLARE_MODULE(epoch_test, mod, SI_SUB_KLD, SI_ORDER_ANY);
MODULE_VERSION(epoch_test, 1);

Event Timeline