Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Jan 2002 15:23:45 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Peter Jeremy <peter.jeremy@alcatel.com.au>
Cc:        Michal Mertl <mime@traveller.cz>, Bruce Evans <bde@zeta.org.au>, Mike Smith <msmith@FreeBSD.ORG>, Bernd Walter <ticso@cicely8.cicely.de>, arch@FreeBSD.ORG
Subject:   Re: When to use atomic_ functions? (was: 64 bit counters)
Message-ID:  <200201022323.g02NNjt60197@apollo.backplane.com>
References:  <200201012349.g01NnKA40071@apollo.backplane.com> <Pine.BSF.4.41.0201021003580.18429-100000@prg.traveller.cz> <20020103095701.B561@gsmx07.alcatel.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help

:This depends on how it is implemented.  Obviously
:	int counter[NCPUS];
:will be just as expensive as performing atomic operations, but no-one
:in their right mind would do that.  One approach is to aggregate all
:the per-CPU counters into a single region of KVM and arrange for that
:KVM to be mapped to different physical memory for each CPU.  (Solaris
:does or did this).  This means that the code to update the counter
:doesn't need to know whether a counter is per-CPU or not.
:
:The code to read the counters _does_ need to know that the counters
:are per-CPU and have to sum all the individual counters - which is
:more expensive than a straight read, but is normally far less frequent.
:
:Peter

    Something like galloc()/gfree().

    offset = galloc(bytes);	/* allocate space in all cpu's per-cpu struct*/
    gfree(offset, bytes);	/* return previously reserved space */

    And then macros to read and write it.

    global_int(offset)		/* returns address of global int @ offset */
    global_quad(offset)		/* returns address of global int @ offset */

    e.g.

    ++*global_quad(ifc->counter_off);

    Which GCC ought to be able to optimize fairly easily.

    This isn't a recommendation, just one way we could do it.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>

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




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