source: trunk/kernel/kern/core.c @ 662

Last change on this file since 662 was 657, checked in by alain, 5 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File size: 3.6 KB
RevLine 
[1]1/*
2 * core.c - core descriptor access function.
[19]3 *
[1]4 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
[564]5 *         Alain Greiner (2016,2017,2018)
[1]6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH.is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
[14]25#include <kernel_config.h>
[457]26#include <hal_kernel_types.h>
[1]27#include <hal_special.h>
28#include <errno.h>
29#include <printk.h>
30#include <thread.h>
[5]31#include <chdev.h>
[188]32#include <dev_pic.h>
[1]33#include <rpc.h>
34#include <cluster.h>
35#include <kmem.h>
36#include <dqdt.h>
37#include <core.h>
38
39/////////////////////////////////
[19]40void core_init( core_t    * core,
41                lid_t       lid,
[5]42                gid_t       gid )
[1]43{
44        core->lid               = lid;
45        core->gid               = gid;
46        core->cycles            = 0;
47        core->time_stamp        = 0;
48        core->ticks_nr          = 0;
49        core->usage             = 0;
50        core->spurious_irqs     = 0;
[19]51        core->fpu_owner         = NULL;
[126]52        core->rand_last         = hal_time_stamp() & 0xFFF;
[1]53
[188]54    // initialize scheduler
[1]55        sched_init( core );
56}
57
[657]58//////////////////////
59lid_t core_lid( void )
60{
61    uint32_t    i;
62
63    // get pointer on local cluser descriptor
64    cluster_t * cluster = LOCAL_CLUSTER;
65
66    // get core gid from hardware register
67    gid_t gid = hal_get_gid();
68
69    // makes an associative search in core_tbl[] from gid
70    for( i = 0 ; i < cluster->cores_nr ; i++ )
71    {
72        if( gid == cluster->core_tbl[i].gid ) return i;
73    }
74
75    assert( false , "core not found" );
76}
77
[1]78//////////////////////////////////////////////
79inline uint32_t core_get_rand( core_t * core )
80{
[19]81        uint32_t value  = ((core->rand_last * CONFIG_RDNG_PARAM_A) +
[101]82                            CONFIG_RDNG_PARAM_C) ^ (hal_get_cycles() & 0xFFF);
[19]83        core->rand_last = value;
84        return value;
[1]85}
86
87////////////////////////////////////
88void core_get_time( core_t   * core,
[23]89                    uint32_t * tm_s, 
[1]90                    uint32_t * tm_us )
91{
[380]92        *tm_s  = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD)/1000;
93        *tm_us = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD*1000)%1000000;
[1]94}
95
96////////////////////////////////
97void core_clock( core_t * core )
98{
99        uint32_t ticks;
100
[367]101        // update ticks counter
102        ticks = core->ticks_nr++;
[1]103
[409]104        // handle scheduler
[408]105        if( (ticks % CONFIG_SCHED_TICKS_PER_QUANTUM) == 0 ) sched_yield( "TICK");
[1]106}
107
108////////////////////////////////////////
[19]109void core_compute_stats( core_t * core )
[1]110{
[443]111        thread_t * idle  = core->scheduler.idle;
[1]112        uint32_t   ticks = core->ticks_nr;
113
114        uint32_t   idle_percent;
115        uint32_t   busy_percent;
116        uint32_t   usage;
117
[19]118        // compute cumulated usage
[1]119        ticks         = (ticks) ? ticks : 1;
120        idle_percent  = (idle->ticks_nr * 100) / ticks;
121        idle_percent  = (idle_percent > 100) ? 100 : idle_percent;
122        busy_percent  = 100 - idle_percent;
123        usage         = (busy_percent + core->usage) / 2;
124
[19]125        // update core descriptor
[1]126        core->usage = usage;
[124]127        hal_fence();
[1]128
129        core->ticks_nr = 0;
130        idle->ticks_nr = 0;
131}
132
133/////////////////////////////////////
134void core_reset_stats( core_t * core )
135{
[443]136        thread_t * idle  = core->scheduler.idle;
137
138        core->ticks_nr = 0;
139        core->usage    = 0;
140        idle->ticks_nr = 0;
141
[124]142        hal_fence();
[1]143}
144
Note: See TracBrowser for help on using the repository browser.