Deleted Added
full compact
tsc.c (302408) tsc.c (305866)
1/*-
2 * Copyright (c) 1998-2003 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998-2003 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/sys/x86/x86/tsc.c 277900 2015-01-29 20:41:42Z jhb $");
28__FBSDID("$FreeBSD: stable/11/sys/x86/x86/tsc.c 305866 2016-09-16 10:04:28Z kib $");
29
30#include "opt_compat.h"
31#include "opt_clock.h"
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/cpu.h>
36#include <sys/limits.h>

--- 6 unchanged lines hidden (view full) ---

43#include <sys/power.h>
44#include <sys/smp.h>
45#include <sys/vdso.h>
46#include <machine/clock.h>
47#include <machine/cputypes.h>
48#include <machine/md_var.h>
49#include <machine/specialreg.h>
50#include <x86/vmware.h>
29
30#include "opt_compat.h"
31#include "opt_clock.h"
32
33#include <sys/param.h>
34#include <sys/bus.h>
35#include <sys/cpu.h>
36#include <sys/limits.h>

--- 6 unchanged lines hidden (view full) ---

43#include <sys/power.h>
44#include <sys/smp.h>
45#include <sys/vdso.h>
46#include <machine/clock.h>
47#include <machine/cputypes.h>
48#include <machine/md_var.h>
49#include <machine/specialreg.h>
50#include <x86/vmware.h>
51#include <dev/acpica/acpi_hpet.h>
51
52#include "cpufreq_if.h"
53
54uint64_t tsc_freq;
55int tsc_is_invariant;
56int tsc_perf_stat;
57
58static eventhandler_tag tsc_levels_tag, tsc_pre_tag, tsc_post_tag;

--- 29 unchanged lines hidden (view full) ---

88 int *status);
89static unsigned tsc_get_timecount(struct timecounter *tc);
90static inline unsigned tsc_get_timecount_low(struct timecounter *tc);
91static unsigned tsc_get_timecount_lfence(struct timecounter *tc);
92static unsigned tsc_get_timecount_low_lfence(struct timecounter *tc);
93static unsigned tsc_get_timecount_mfence(struct timecounter *tc);
94static unsigned tsc_get_timecount_low_mfence(struct timecounter *tc);
95static void tsc_levels_changed(void *arg, int unit);
52
53#include "cpufreq_if.h"
54
55uint64_t tsc_freq;
56int tsc_is_invariant;
57int tsc_perf_stat;
58
59static eventhandler_tag tsc_levels_tag, tsc_pre_tag, tsc_post_tag;

--- 29 unchanged lines hidden (view full) ---

89 int *status);
90static unsigned tsc_get_timecount(struct timecounter *tc);
91static inline unsigned tsc_get_timecount_low(struct timecounter *tc);
92static unsigned tsc_get_timecount_lfence(struct timecounter *tc);
93static unsigned tsc_get_timecount_low_lfence(struct timecounter *tc);
94static unsigned tsc_get_timecount_mfence(struct timecounter *tc);
95static unsigned tsc_get_timecount_low_mfence(struct timecounter *tc);
96static void tsc_levels_changed(void *arg, int unit);
97static uint32_t x86_tsc_vdso_timehands(struct vdso_timehands *vdso_th,
98 struct timecounter *tc);
99#ifdef COMPAT_FREEBSD32
100static uint32_t x86_tsc_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
101 struct timecounter *tc);
102#endif
96
97static struct timecounter tsc_timecounter = {
103
104static struct timecounter tsc_timecounter = {
98 tsc_get_timecount, /* get_timecount */
99 0, /* no poll_pps */
100 ~0u, /* counter_mask */
101 0, /* frequency */
102 "TSC", /* name */
103 800, /* quality (adjusted in code) */
105 .tc_get_timecount = tsc_get_timecount,
106 .tc_counter_mask = ~0u,
107 .tc_name = "TSC",
108 .tc_quality = 800, /* adjusted in code */
109 .tc_fill_vdso_timehands = x86_tsc_vdso_timehands,
110#ifdef COMPAT_FREEBSD32
111 .tc_fill_vdso_timehands32 = x86_tsc_vdso_timehands32,
112#endif
104};
105
106static void
107tsc_freq_vmware(void)
108{
109 u_int regs[4];
110
111 if (hv_high >= 0x40000010) {

--- 607 unchanged lines hidden (view full) ---

719static u_int
720tsc_get_timecount_low_mfence(struct timecounter *tc)
721{
722
723 mfence();
724 return (tsc_get_timecount_low(tc));
725}
726
113};
114
115static void
116tsc_freq_vmware(void)
117{
118 u_int regs[4];
119
120 if (hv_high >= 0x40000010) {

--- 607 unchanged lines hidden (view full) ---

728static u_int
729tsc_get_timecount_low_mfence(struct timecounter *tc)
730{
731
732 mfence();
733 return (tsc_get_timecount_low(tc));
734}
735
727uint32_t
728cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th, struct timecounter *tc)
736static uint32_t
737x86_tsc_vdso_timehands(struct vdso_timehands *vdso_th, struct timecounter *tc)
729{
730
738{
739
740 vdso_th->th_algo = VDSO_TH_ALGO_X86_TSC;
731 vdso_th->th_x86_shift = (int)(intptr_t)tc->tc_priv;
741 vdso_th->th_x86_shift = (int)(intptr_t)tc->tc_priv;
742 vdso_th->th_x86_hpet_idx = 0xffffffff;
732 bzero(vdso_th->th_res, sizeof(vdso_th->th_res));
743 bzero(vdso_th->th_res, sizeof(vdso_th->th_res));
733 return (tc == &tsc_timecounter);
744 return (1);
734}
735
736#ifdef COMPAT_FREEBSD32
745}
746
747#ifdef COMPAT_FREEBSD32
737uint32_t
738cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
748static uint32_t
749x86_tsc_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
739 struct timecounter *tc)
740{
741
750 struct timecounter *tc)
751{
752
753 vdso_th32->th_algo = VDSO_TH_ALGO_X86_TSC;
742 vdso_th32->th_x86_shift = (int)(intptr_t)tc->tc_priv;
754 vdso_th32->th_x86_shift = (int)(intptr_t)tc->tc_priv;
755 vdso_th32->th_x86_hpet_idx = 0xffffffff;
743 bzero(vdso_th32->th_res, sizeof(vdso_th32->th_res));
756 bzero(vdso_th32->th_res, sizeof(vdso_th32->th_res));
744 return (tc == &tsc_timecounter);
757 return (1);
745}
746#endif
758}
759#endif