2015-04-13 14:43:10 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2012 Konstantin Belousov <kib@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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MACHINE_COUNTER_H_
|
|
|
|
#define _MACHINE_COUNTER_H_
|
|
|
|
|
|
|
|
#include <sys/pcpu.h>
|
2017-02-06 17:20:37 +00:00
|
|
|
#include <machine/atomic.h>
|
2015-04-13 14:43:10 +00:00
|
|
|
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
extern struct pcpu __pcpu[];
|
2017-04-17 18:57:26 +00:00
|
|
|
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
#define EARLY_COUNTER &__pcpu[0].pc_early_dummy_counter
|
|
|
|
|
2017-02-06 17:20:37 +00:00
|
|
|
#define counter_enter() do {} while (0)
|
|
|
|
#define counter_exit() do {} while (0)
|
2015-04-13 14:43:10 +00:00
|
|
|
|
|
|
|
#ifdef IN_SUBR_COUNTER_C
|
|
|
|
static inline uint64_t
|
|
|
|
counter_u64_read_one(uint64_t *p, int cpu)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (*(uint64_t *)((char *)p + sizeof(struct pcpu) * cpu));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t
|
|
|
|
counter_u64_fetch_inline(uint64_t *p)
|
|
|
|
{
|
|
|
|
uint64_t r;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
r = 0;
|
2017-02-06 17:20:37 +00:00
|
|
|
CPU_FOREACH(i)
|
2015-04-13 14:43:10 +00:00
|
|
|
r += counter_u64_read_one((uint64_t *)p, i);
|
|
|
|
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
counter_u64_zero_one_cpu(void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
*((uint64_t *)((char *)arg + sizeof(struct pcpu) *
|
|
|
|
PCPU_GET(cpuid))) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
counter_u64_zero_inline(counter_u64_t c)
|
|
|
|
{
|
|
|
|
|
2017-04-09 02:00:03 +00:00
|
|
|
smp_rendezvous(smp_no_rendezvous_barrier, counter_u64_zero_one_cpu,
|
|
|
|
smp_no_rendezvous_barrier, c);
|
2015-04-13 14:43:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-06 17:20:37 +00:00
|
|
|
#define counter_u64_add_protected(c, inc) counter_u64_add(c, inc)
|
2015-04-13 14:43:10 +00:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
counter_u64_add(counter_u64_t c, int64_t inc)
|
|
|
|
{
|
|
|
|
|
2017-02-06 17:20:37 +00:00
|
|
|
atomic_add_64((uint64_t *)zpcpu_get(c), inc);
|
2015-04-13 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! _MACHINE_COUNTER_H_ */
|