Deleted Added
full compact
tsc.c (118550) tsc.c (118987)
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

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

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
28#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

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

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
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/i386/i386/tsc.c 118550 2003-08-06 15:05:27Z phk $");
29__FBSDID("$FreeBSD: head/sys/i386/i386/tsc.c 118987 2003-08-16 08:23:53Z phk $");
30
31#include "opt_clock.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
36#include <sys/time.h>
37#include <sys/timetc.h>

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

55
56static unsigned tsc_get_timecount(struct timecounter *tc);
57
58static struct timecounter tsc_timecounter = {
59 tsc_get_timecount, /* get_timecount */
60 0, /* no poll_pps */
61 ~0u, /* counter_mask */
62 0, /* frequency */
30
31#include "opt_clock.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
36#include <sys/time.h>
37#include <sys/timetc.h>

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

55
56static unsigned tsc_get_timecount(struct timecounter *tc);
57
58static struct timecounter tsc_timecounter = {
59 tsc_get_timecount, /* get_timecount */
60 0, /* no poll_pps */
61 ~0u, /* counter_mask */
62 0, /* frequency */
63 "TSC" /* name */
63 "TSC", /* name */
64 800, /* quality (adjusted in code) */
64};
65
66void
67init_TSC(void)
68{
69 u_int64_t tscval[2];
70
71 if (cpu_feature & CPUID_TSC)

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

81
82 tscval[0] = rdtsc();
83 DELAY(1000000);
84 tscval[1] = rdtsc();
85
86 tsc_freq = tscval[1] - tscval[0];
87 if (bootverbose)
88 printf("TSC clock: %ju Hz\n", (intmax_t)tsc_freq);
65};
66
67void
68init_TSC(void)
69{
70 u_int64_t tscval[2];
71
72 if (cpu_feature & CPUID_TSC)

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

82
83 tscval[0] = rdtsc();
84 DELAY(1000000);
85 tscval[1] = rdtsc();
86
87 tsc_freq = tscval[1] - tscval[0];
88 if (bootverbose)
89 printf("TSC clock: %ju Hz\n", (intmax_t)tsc_freq);
89
90#ifdef SMP
91 /*
92 * We can not use the TSC in SMP mode unless the TSCs on all CPUs
93 * are somehow synchronized. Some hardware configurations do
94 * this, but we have no way of determining whether this is the
95 * case, so we do not use the TSC in multi-processor systems
96 * unless the user indicated (by setting kern.timecounter.smp_tsc
97 * to 1) that he believes that his TSCs are synchronized.
98 */
99 if (mp_ncpus > 1 && !smp_tsc)
100 return;
101#endif
102 return;
103}
104
105
106void
107init_TSC_tc(void)
108{
109 /*
110 * We can not use the TSC if we support APM. Precise timekeeping
111 * on an APM'ed machine is at best a fools pursuit, since
112 * any and all of the time spent in various SMM code can't
113 * be reliably accounted for. Reading the RTC is your only
114 * source of reliable time info. The i8254 looses too of course
115 * but we need to have some kind of time...
116 * We don't know at this point whether APM is going to be used
117 * or not, nor when it might be activated. Play it safe.
118 */
119 if (power_pm_get_type() == POWER_PM_TYPE_APM) {
90}
91
92
93void
94init_TSC_tc(void)
95{
96 /*
97 * We can not use the TSC if we support APM. Precise timekeeping
98 * on an APM'ed machine is at best a fools pursuit, since
99 * any and all of the time spent in various SMM code can't
100 * be reliably accounted for. Reading the RTC is your only
101 * source of reliable time info. The i8254 looses too of course
102 * but we need to have some kind of time...
103 * We don't know at this point whether APM is going to be used
104 * or not, nor when it might be activated. Play it safe.
105 */
106 if (power_pm_get_type() == POWER_PM_TYPE_APM) {
107 tsc_timecounter.tc_quality = -1000;
120 if (bootverbose)
121 printf("TSC timecounter disabled: APM enabled.\n");
108 if (bootverbose)
109 printf("TSC timecounter disabled: APM enabled.\n");
122 return;
123 }
124
110 }
111
112#ifdef SMP
113 /*
114 * We can not use the TSC in SMP mode unless the TSCs on all CPUs
115 * are somehow synchronized. Some hardware configurations do
116 * this, but we have no way of determining whether this is the
117 * case, so we do not use the TSC in multi-processor systems
118 * unless the user indicated (by setting kern.timecounter.smp_tsc
119 * to 1) that he believes that his TSCs are synchronized.
120 */
121 if (mp_ncpus > 1 && !smp_tsc)
122 tsc_timecounter.tc_quality = -100;
123#endif
124
125 if (tsc_present && tsc_freq != 0 && !tsc_is_broken) {
126 tsc_timecounter.tc_frequency = tsc_freq;
127 tc_init(&tsc_timecounter);
128 }
125 if (tsc_present && tsc_freq != 0 && !tsc_is_broken) {
126 tsc_timecounter.tc_frequency = tsc_freq;
127 tc_init(&tsc_timecounter);
128 }
129
130 return;
131}
132
133static int
134sysctl_machdep_tsc_freq(SYSCTL_HANDLER_ARGS)
135{
136 int error;
137 uint64_t freq;
138

--- 19 unchanged lines hidden ---
129}
130
131static int
132sysctl_machdep_tsc_freq(SYSCTL_HANDLER_ARGS)
133{
134 int error;
135 uint64_t freq;
136

--- 19 unchanged lines hidden ---