The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/subr_pcpu.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2001 Wind River Systems, Inc.
    3  * All rights reserved.
    4  * Written by: John Baldwin <jhb@FreeBSD.org>
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 4. Neither the name of the author nor the names of any co-contributors
   15  *    may be used to endorse or promote products derived from this software
   16  *    without specific prior written permission.
   17  *
   18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28  * SUCH DAMAGE.
   29  */
   30 
   31 /*
   32  * This module provides MI support for per-cpu data.
   33  *
   34  * Each architecture determines the mapping of logical CPU IDs to physical
   35  * CPUs.  The requirements of this mapping are as follows:
   36  *  - Logical CPU IDs must reside in the range 0 ... MAXCPU - 1.
   37  *  - The mapping is not required to be dense.  That is, there may be
   38  *    gaps in the mappings.
   39  *  - The platform sets the value of MAXCPU in <machine/param.h>.
   40  *  - It is suggested, but not required, that in the non-SMP case, the
   41  *    platform define MAXCPU to be 1 and define the logical ID of the
   42  *    sole CPU as 0.
   43  */
   44 
   45 #include <sys/cdefs.h>
   46 __FBSDID("$FreeBSD: releng/6.4/sys/kern/subr_pcpu.c 152319 2005-11-11 18:50:45Z jhb $");
   47 
   48 #include "opt_ddb.h"
   49 
   50 #include <sys/param.h>
   51 #include <sys/systm.h>
   52 #include <sys/linker_set.h>
   53 #include <sys/lock.h>
   54 #include <sys/pcpu.h>
   55 #include <sys/proc.h>
   56 #include <sys/smp.h>
   57 #include <ddb/ddb.h>
   58 
   59 static struct pcpu *cpuid_to_pcpu[MAXCPU];
   60 struct cpuhead cpuhead = SLIST_HEAD_INITIALIZER(cpuhead);
   61 
   62 /*
   63  * Initialize the MI portions of a struct pcpu.
   64  */
   65 void
   66 pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
   67 {
   68 
   69         bzero(pcpu, size);
   70         KASSERT(cpuid >= 0 && cpuid < MAXCPU,
   71             ("pcpu_init: invalid cpuid %d", cpuid));
   72         pcpu->pc_cpuid = cpuid;
   73         pcpu->pc_cpumask = 1 << cpuid;
   74         cpuid_to_pcpu[cpuid] = pcpu;
   75         SLIST_INSERT_HEAD(&cpuhead, pcpu, pc_allcpu);
   76         cpu_pcpu_init(pcpu, cpuid, size);
   77 }
   78 
   79 /*
   80  * Destroy a struct pcpu.
   81  */
   82 void
   83 pcpu_destroy(struct pcpu *pcpu)
   84 {
   85 
   86         SLIST_REMOVE(&cpuhead, pcpu, pcpu, pc_allcpu);
   87         cpuid_to_pcpu[pcpu->pc_cpuid] = NULL;
   88 }
   89 
   90 /*
   91  * Locate a struct pcpu by cpu id.
   92  */
   93 struct pcpu *
   94 pcpu_find(u_int cpuid)
   95 {
   96 
   97         return (cpuid_to_pcpu[cpuid]);
   98 }
   99 
  100 #ifdef DDB
  101 
  102 static void
  103 show_pcpu(struct pcpu *pc)
  104 {
  105         struct thread *td;
  106 
  107         db_printf("cpuid        = %d\n", pc->pc_cpuid);
  108         db_printf("curthread    = ");
  109         td = pc->pc_curthread;
  110         if (td != NULL)
  111                 db_printf("%p: pid %d \"%s\"\n", td, td->td_proc->p_pid,
  112                     td->td_proc->p_comm);
  113         else
  114                 db_printf("none\n");
  115         db_printf("curpcb       = %p\n", pc->pc_curpcb);
  116         db_printf("fpcurthread  = ");
  117         td = pc->pc_fpcurthread;
  118         if (td != NULL)
  119                 db_printf("%p: pid %d \"%s\"\n", td, td->td_proc->p_pid,
  120                     td->td_proc->p_comm);
  121         else
  122                 db_printf("none\n");
  123         db_printf("idlethread   = ");
  124         td = pc->pc_idlethread;
  125         if (td != NULL)
  126                 db_printf("%p: pid %d \"%s\"\n", td, td->td_proc->p_pid,
  127                     td->td_proc->p_comm);
  128         else
  129                 db_printf("none\n");
  130         db_show_mdpcpu(pc);
  131                 
  132 #ifdef WITNESS
  133         db_printf("spin locks held:\n");
  134         witness_list_locks(&pc->pc_spinlocks);
  135 #endif
  136 }
  137 
  138 DB_SHOW_COMMAND(pcpu, db_show_pcpu)
  139 {
  140         struct pcpu *pc;
  141         int id;
  142 
  143         if (have_addr)
  144                 id = ((addr >> 4) % 16) * 10 + (addr % 16);
  145         else
  146                 id = PCPU_GET(cpuid);
  147         pc = pcpu_find(id);
  148         if (pc == NULL) {
  149                 db_printf("CPU %d not found\n", id);
  150                 return;
  151         }
  152         show_pcpu(pc);
  153 }
  154 
  155 DB_SHOW_COMMAND(allpcpu, db_show_cpu_all)
  156 {
  157         struct pcpu *pc;
  158         int id;
  159 
  160         db_printf("Current CPU: %d\n\n", PCPU_GET(cpuid));
  161         for (id = 0; id <= mp_maxid; id++) {
  162                 pc = pcpu_find(id);
  163                 if (pc != NULL) {
  164                         show_pcpu(pc);
  165                         db_printf("\n");
  166                 }
  167         }
  168 }
  169 #endif

Cache object: d65a48a2a9e88dba58af2d9b8ae1d94f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.