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

Last change on this file since 437 was 433, checked in by alain, 6 years ago

blip

File size: 3.3 KB
Line 
1/*
2 * core.c - core descriptor access function.
3 *
4 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *         Alain Greiner (2016,2017)
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
25#include <kernel_config.h>
26#include <hal_types.h>
27#include <hal_special.h>
28#include <errno.h>
29#include <printk.h>
30#include <thread.h>
31#include <chdev.h>
32#include <dev_pic.h>
33#include <rpc.h>
34#include <cluster.h>
35#include <kmem.h>
36#include <dqdt.h>
37#include <core.h>
38
39/////////////////////////////////
40void core_init( core_t    * core,
41                lid_t       lid,
42                gid_t       gid )
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;
51        core->thread_idle       = NULL;
52        core->fpu_owner         = NULL;
53        core->rand_last         = hal_time_stamp() & 0xFFF;
54
55    // initialize scheduler
56        sched_init( core );
57}
58
59//////////////////////////////////////////////
60inline uint32_t core_get_rand( core_t * core )
61{
62        uint32_t value  = ((core->rand_last * CONFIG_RDNG_PARAM_A) +
63                            CONFIG_RDNG_PARAM_C) ^ (hal_get_cycles() & 0xFFF);
64        core->rand_last = value;
65        return value;
66}
67
68////////////////////////////////////
69void core_get_time( core_t   * core,
70                    uint32_t * tm_s, 
71                    uint32_t * tm_us )
72{
73        *tm_s  = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD)/1000;
74        *tm_us = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD*1000)%1000000;
75}
76
77////////////////////////////////
78void core_clock( core_t * core )
79{
80        uint32_t ticks;
81
82        // update ticks counter
83        ticks = core->ticks_nr++;
84
85        // handle scheduler
86        if( (ticks % CONFIG_SCHED_TICKS_PER_QUANTUM) == 0 ) sched_yield( "TICK");
87
88        // update DQDT
89        if( ((ticks % CONFIG_DQDT_TICKS_PER_QUANTUM) == 0) && (core->lid == 0) )
90        dqdt_global_update();
91}
92
93////////////////////////////////////////
94void core_compute_stats( core_t * core )
95{
96        thread_t * idle  = core->thread_idle;
97        uint32_t   ticks = core->ticks_nr;
98
99        uint32_t   idle_percent;
100        uint32_t   busy_percent;
101        uint32_t   usage;
102
103        // compute cumulated usage
104        ticks         = (ticks) ? ticks : 1;
105        idle_percent  = (idle->ticks_nr * 100) / ticks;
106        idle_percent  = (idle_percent > 100) ? 100 : idle_percent;
107        busy_percent  = 100 - idle_percent;
108        usage         = (busy_percent + core->usage) / 2;
109
110        // update core descriptor
111        core->usage = usage;
112        hal_fence();
113
114        core->ticks_nr = 0;
115        idle->ticks_nr = 0;
116}
117
118/////////////////////////////////////
119void core_reset_stats( core_t * core )
120{
121        core->ticks_nr              = 0;
122        core->usage                 = 0;
123        core->thread_idle->ticks_nr = 0;
124        hal_fence();
125}
126
Note: See TracBrowser for help on using the repository browser.