Subject: per-cpu data
To: None <tech-kern@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 09/21/2004 19:20:33
--NextPart-20040921191637-1514800
Content-Type: Text/Plain; charset=us-ascii

hi,

currently per-cpu MI/MD data are mixed up in cpu_info.
the attached diff is to split them so that MI members can be added
without touching every ports.

any comments?

YAMAMOTO Takashi

--NextPart-20040921191637-1514800
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="cpu_data.h"

/*	$NetBSD$	*/

/*-
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * William Jolitz.
 *
 * 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.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
 *
 *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
 */
/*
 * from arch/i386/include/cpu.h:
 *	NetBSD: cpu.h,v 1.115 2004/05/16 12:32:53 yamt Exp
 */

#ifndef _CPU_DATA_H_
#define	_CPU_DATA_H_

#if defined(_KERNEL_OPT)
#include "opt_multiprocessor.h"
#endif

struct lwp;
#include <sys/sched.h>	/* for schedstate_percpu */

/*
 * MI per-cpu data
 */

struct cpu_data {
	struct schedstate_percpu cpu_schedstate; /* scheduler state */
	struct lwp *cpu_curlwp;		/* current owner of the processor */
	cpuid_t cpu_cpuid;		/* our CPU ID */

	/*
	 * Variables used by cc_microtime().
	 */
	struct timeval cpu_cc_time;
	int64_t cpu_cc_cc;
	int64_t cpu_cc_ms_delta;
	int64_t cpu_cc_denom;

	/*
	 * for LOCKDEBUG
	 */
	u_long cpu_spin_locks;		/* # of spin locks held */
	u_long cpu_simple_locks;	/* # of simple locks held */
};

/* compat definitions */
#define	ci_schedstate	ci_data.cpu_schedstate
#define	ci_curlwp	ci_data.cpu_curlwp
#define	ci_cpuid	ci_data.cpu_cpuid
#define	ci_cc_time	ci_data.cpu_cc_time
#define	ci_cc_cc	ci_data.cpu_cc_cc
#define	ci_cc_ms_delta	ci_data.cpu_cc_ms_delta
#define	ci_cc_denom	ci_data.cpu_cc_denom
#define	ci_spin_locks	ci_data.cpu_spin_locks
#define	ci_simple_locks	ci_data.cpu_simple_locks

#endif /* _CPU_DATA_H_ */

--NextPart-20040921191637-1514800
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="a.diff"

Index: arch/i386/include/cpu.h
===================================================================
--- arch/i386/include/cpu.h	(revision 828)
+++ arch/i386/include/cpu.h	(working copy)
@@ -57,6 +57,7 @@
 #include <sys/device.h>
 #include <sys/lock.h>			/* will also get LOCKDEBUG */
 #include <sys/sched.h>
+#include <sys/cpu_data.h>
 
 #include <lib/libkern/libkern.h>	/* offsetof */
 
@@ -72,22 +73,18 @@ struct cpu_info {
 	struct cpu_info *ci_self;	/* self-pointer */
 	void	*ci_tlog_base;		/* Trap log base */
 	int32_t ci_tlog_offset;		/* Trap log current offset */
-	struct schedstate_percpu ci_schedstate; /* scheduler state */
 	struct cpu_info *ci_next;	/* next cpu */
 
 	/*
 	 * Public members.
 	 */
-	struct lwp *ci_curlwp;		/* current owner of the processor */
 	struct simplelock ci_slock;	/* lock on this data structure */
-	cpuid_t ci_cpuid;		/* our CPU ID */
-	u_int ci_apicid;		/* our APIC ID */
-	u_long ci_spin_locks;		/* # of spin locks held */
-	u_long ci_simple_locks;		/* # of simple locks held */
+	struct cpu_data ci_data;	/* MI per-cpu data */
 
 	/*
 	 * Private members.
 	 */
+	u_int ci_apicid;		/* our APIC ID */
 	struct lwp *ci_fpcurlwp;	/* current owner of the FPU */
 	int	ci_fpsaving;		/* save in progress */
 
@@ -138,14 +135,6 @@ struct cpu_info {
 	u_int ci_cflush_lsize;	/* CFLUSH insn line size */
 	struct x86_cache_info ci_cinfo[CAI_COUNT];
 
-	/*
-	 * Variables used by cc_microtime().
-	 */
-	struct timeval ci_cc_time;
-	int64_t ci_cc_cc;
-	int64_t ci_cc_ms_delta;
-	int64_t ci_cc_denom;
-
 	union descriptor *ci_gdt;
 
 	struct i386tss	ci_doubleflt_tss;

--NextPart-20040921191637-1514800--