From owner-svn-src-head@FreeBSD.ORG Tue Jul 9 23:47:29 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D57DDF1F; Tue, 9 Jul 2013 23:47:29 +0000 (UTC) (envelope-from obrien@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id C821E1691; Tue, 9 Jul 2013 23:47:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r69NlTmF092047; Tue, 9 Jul 2013 23:47:29 GMT (envelope-from obrien@svn.freebsd.org) Received: (from obrien@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r69NlTVK092043; Tue, 9 Jul 2013 23:47:29 GMT (envelope-from obrien@svn.freebsd.org) Message-Id: <201307092347.r69NlTVK092043@svn.freebsd.org> From: "David E. O'Brien" Date: Tue, 9 Jul 2013 23:47:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r253122 - head/sys/dev/random X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jul 2013 23:47:29 -0000 Author: obrien Date: Tue Jul 9 23:47:28 2013 New Revision: 253122 URL: http://svnweb.freebsd.org/changeset/base/253122 Log: Refactor random_systat to be a *random_systat. This avoids unnecessary structure copying in random_ident_hardware(). This change will also help further modularization of random(4) subsystem. Submitted by: arthurmesh@gmail.com Reviewed by: obrien Obtained from: Juniper Networks Modified: head/sys/dev/random/probe.c head/sys/dev/random/randomdev.c head/sys/dev/random/randomdev.h head/sys/dev/random/randomdev_soft.c Modified: head/sys/dev/random/probe.c ============================================================================== --- head/sys/dev/random/probe.c Tue Jul 9 23:21:57 2013 (r253121) +++ head/sys/dev/random/probe.c Tue Jul 9 23:47:28 2013 (r253122) @@ -61,11 +61,11 @@ extern struct random_systat random_ivy; #endif void -random_ident_hardware(struct random_systat *systat) +random_ident_hardware(struct random_systat **systat) { /* Set default to software */ - *systat = random_yarrow; + *systat = &random_yarrow; /* Then go looking for hardware */ #if defined(__amd64__) || (defined(__i386__) && !defined(PC98)) @@ -76,7 +76,7 @@ random_ident_hardware(struct random_syst enable = 1; TUNABLE_INT_FETCH("hw.nehemiah_rng_enable", &enable); if (enable) - *systat = random_nehemiah; + *systat = &random_nehemiah; } #endif #ifdef RDRAND_RNG @@ -86,7 +86,7 @@ random_ident_hardware(struct random_syst enable = 1; TUNABLE_INT_FETCH("hw.ivy_rng_enable", &enable); if (enable) - *systat = random_ivy; + *systat = &random_ivy; } #endif #endif Modified: head/sys/dev/random/randomdev.c ============================================================================== --- head/sys/dev/random/randomdev.c Tue Jul 9 23:21:57 2013 (r253121) +++ head/sys/dev/random/randomdev.c Tue Jul 9 23:47:28 2013 (r253122) @@ -70,7 +70,7 @@ static struct cdevsw random_cdevsw = { .d_name = "random", }; -struct random_systat random_systat; +struct random_systat *random_systat; /* For use with make_dev(9)/destroy_dev(9). */ static struct cdev *random_dev; @@ -88,8 +88,8 @@ random_close(struct cdev *dev __unused, { if ((flags & FWRITE) && (priv_check(td, PRIV_RANDOM_RESEED) == 0) && (securelevel_gt(td->td_ucred, 0) == 0)) { - (*random_systat.reseed)(); - random_systat.seeded = 1; + (*random_systat->reseed)(); + random_systat->seeded = 1; arc4rand(NULL, 0, 1); /* Reseed arc4random as well. */ } @@ -104,8 +104,8 @@ random_read(struct cdev *dev __unused, s void *random_buf; /* Blocking logic */ - if (!random_systat.seeded) - error = (*random_systat.block)(flag); + if (!random_systat->seeded) + error = (*random_systat->block)(flag); /* The actual read */ if (!error) { @@ -114,7 +114,7 @@ random_read(struct cdev *dev __unused, s while (uio->uio_resid > 0 && !error) { c = MIN(uio->uio_resid, PAGE_SIZE); - c = (*random_systat.read)(random_buf, c); + c = (*random_systat->read)(random_buf, c); error = uiomove(random_buf, c, uio); } @@ -139,7 +139,7 @@ random_write(struct cdev *dev __unused, error = uiomove(random_buf, c, uio); if (error) break; - (*random_systat.write)(random_buf, c); + (*random_systat->write)(random_buf, c); } free(random_buf, M_TEMP); @@ -172,10 +172,10 @@ random_poll(struct cdev *dev __unused, i int revents = 0; if (events & (POLLIN | POLLRDNORM)) { - if (random_systat.seeded) + if (random_systat->seeded) revents = events & (POLLIN | POLLRDNORM); else - revents = (*random_systat.poll) (events,td); + revents = (*random_systat->poll) (events,td); } return (revents); } @@ -189,11 +189,11 @@ random_modevent(module_t mod __unused, i switch (type) { case MOD_LOAD: random_ident_hardware(&random_systat); - (*random_systat.init)(); + (*random_systat->init)(); if (bootverbose) printf("random: \n", - random_systat.ident); + random_systat->ident); random_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &random_cdevsw, RANDOM_MINOR, NULL, UID_ROOT, GID_WHEEL, 0666, "random"); @@ -202,7 +202,7 @@ random_modevent(module_t mod __unused, i break; case MOD_UNLOAD: - (*random_systat.deinit)(); + (*random_systat->deinit)(); destroy_dev(random_dev); Modified: head/sys/dev/random/randomdev.h ============================================================================== --- head/sys/dev/random/randomdev.h Tue Jul 9 23:21:57 2013 (r253121) +++ head/sys/dev/random/randomdev.h Tue Jul 9 23:47:28 2013 (r253122) @@ -51,7 +51,7 @@ struct random_systat { random_reseed_func_t *reseed; }; -extern struct random_systat random_systat; +extern struct random_systat *random_systat; -extern void random_ident_hardware(struct random_systat *); +extern void random_ident_hardware(struct random_systat **); extern void random_null_func(void); Modified: head/sys/dev/random/randomdev_soft.c ============================================================================== --- head/sys/dev/random/randomdev_soft.c Tue Jul 9 23:21:57 2013 (r253121) +++ head/sys/dev/random/randomdev_soft.c Tue Jul 9 23:47:28 2013 (r253122) @@ -138,7 +138,7 @@ random_yarrow_init(void) SYSCTL_ADD_PROC(&random_clist, SYSCTL_CHILDREN(random_sys_o), OID_AUTO, "seeded", CTLTYPE_INT | CTLFLAG_RW, - &random_systat.seeded, 1, random_check_boolean, "I", + &random_systat->seeded, 1, random_check_boolean, "I", "Seeded State"); random_sys_harvest_o = SYSCTL_ADD_NODE(&random_clist, @@ -362,10 +362,10 @@ random_yarrow_write(void *buf, int count void random_yarrow_unblock(void) { - if (!random_systat.seeded) { - random_systat.seeded = 1; - selwakeuppri(&random_systat.rsel, PUSER); - wakeup(&random_systat); + if (!random_systat->seeded) { + random_systat->seeded = 1; + selwakeuppri(&random_systat->rsel, PUSER); + wakeup(random_systat); } (void)atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_NONE, ARC4_ENTR_HAVE); @@ -377,10 +377,10 @@ random_yarrow_poll(int events, struct th int revents = 0; mtx_lock(&random_reseed_mtx); - if (random_systat.seeded) + if (random_systat->seeded) revents = events & (POLLIN | POLLRDNORM); else - selrecord(td, &random_systat.rsel); + selrecord(td, &random_systat->rsel); mtx_unlock(&random_reseed_mtx); return revents; @@ -394,12 +394,12 @@ random_yarrow_block(int flag) mtx_lock(&random_reseed_mtx); /* Blocking logic */ - while (!random_systat.seeded && !error) { + while (!random_systat->seeded && !error) { if (flag & O_NONBLOCK) error = EWOULDBLOCK; else { printf("Entropy device is blocking.\n"); - error = msleep(&random_systat, + error = msleep(random_systat, &random_reseed_mtx, PUSER | PCATCH, "block", 0); }