[1] | 1 | /* |
---|
| 2 | * core.c - core descriptor access function. |
---|
[19] | 3 | * |
---|
[1] | 4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
[68] | 5 | * Alain Greiner (2016,2017) |
---|
[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> |
---|
[1] | 26 | #include <hal_types.h> |
---|
| 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] | 40 | void 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->thread_idle = NULL; |
---|
| 52 | core->fpu_owner = NULL; |
---|
[126] | 53 | core->rand_last = hal_time_stamp() & 0xFFF; |
---|
[1] | 54 | |
---|
[188] | 55 | // initialize scheduler |
---|
[1] | 56 | sched_init( core ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ////////////////////////////////////////////// |
---|
| 60 | inline uint32_t core_get_rand( core_t * core ) |
---|
| 61 | { |
---|
[19] | 62 | uint32_t value = ((core->rand_last * CONFIG_RDNG_PARAM_A) + |
---|
[101] | 63 | CONFIG_RDNG_PARAM_C) ^ (hal_get_cycles() & 0xFFF); |
---|
[19] | 64 | core->rand_last = value; |
---|
| 65 | return value; |
---|
[1] | 66 | } |
---|
| 67 | |
---|
| 68 | //////////////////////////////////// |
---|
| 69 | void core_get_time( core_t * core, |
---|
[23] | 70 | uint32_t * tm_s, |
---|
[1] | 71 | uint32_t * tm_us ) |
---|
| 72 | { |
---|
[380] | 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; |
---|
[1] | 75 | } |
---|
| 76 | |
---|
[367] | 77 | /* deprecated 14/08/2017 [AG] |
---|
[1] | 78 | ////////////////////////////////////// |
---|
| 79 | void core_time_update( core_t * core ) |
---|
| 80 | { |
---|
[19] | 81 | uint32_t elapsed; |
---|
[1] | 82 | uint32_t ticks_nr = core->ticks_nr; |
---|
| 83 | uint64_t cycles = core->cycles; |
---|
| 84 | uint32_t time_stamp = core->time_stamp; |
---|
[101] | 85 | uint32_t time_now = hal_get_cycles(); |
---|
[1] | 86 | |
---|
[19] | 87 | // compute number of elapsed cycles taking into account 32 bits register wrap |
---|
[1] | 88 | if( time_now < time_stamp ) elapsed = (0xFFFFFFFF - time_stamp) + time_now; |
---|
| 89 | else elapsed = time_now - time_stamp; |
---|
[19] | 90 | |
---|
[1] | 91 | cycles += elapsed; |
---|
| 92 | ticks_nr = elapsed / core->ticks_period; |
---|
| 93 | |
---|
| 94 | core->time_stamp = time_now; |
---|
| 95 | core->cycles = cycles + elapsed; |
---|
| 96 | core->ticks_nr = ticks_nr + (elapsed / core->ticks_period); |
---|
[124] | 97 | hal_fence(); |
---|
[1] | 98 | } |
---|
[367] | 99 | */ |
---|
[1] | 100 | |
---|
| 101 | //////////////////////////////// |
---|
| 102 | void core_clock( core_t * core ) |
---|
| 103 | { |
---|
| 104 | uint32_t ticks; |
---|
| 105 | |
---|
[367] | 106 | // update ticks counter |
---|
| 107 | ticks = core->ticks_nr++; |
---|
[1] | 108 | |
---|
[409] | 109 | // handle scheduler |
---|
[408] | 110 | if( (ticks % CONFIG_SCHED_TICKS_PER_QUANTUM) == 0 ) sched_yield( "TICK"); |
---|
[19] | 111 | |
---|
[406] | 112 | // update DQDT |
---|
[367] | 113 | if( ((ticks % CONFIG_DQDT_TICKS_PER_QUANTUM) == 0) && (core->lid == 0) ) |
---|
| 114 | dqdt_global_update(); |
---|
[1] | 115 | } |
---|
| 116 | |
---|
| 117 | //////////////////////////////////////// |
---|
[19] | 118 | void core_compute_stats( core_t * core ) |
---|
[1] | 119 | { |
---|
| 120 | thread_t * idle = core->thread_idle; |
---|
| 121 | uint32_t ticks = core->ticks_nr; |
---|
| 122 | |
---|
| 123 | uint32_t idle_percent; |
---|
| 124 | uint32_t busy_percent; |
---|
| 125 | uint32_t usage; |
---|
| 126 | |
---|
[19] | 127 | // compute cumulated usage |
---|
[1] | 128 | ticks = (ticks) ? ticks : 1; |
---|
| 129 | idle_percent = (idle->ticks_nr * 100) / ticks; |
---|
| 130 | idle_percent = (idle_percent > 100) ? 100 : idle_percent; |
---|
| 131 | busy_percent = 100 - idle_percent; |
---|
| 132 | usage = (busy_percent + core->usage) / 2; |
---|
| 133 | |
---|
[19] | 134 | // update core descriptor |
---|
[1] | 135 | core->usage = usage; |
---|
[124] | 136 | hal_fence(); |
---|
[1] | 137 | |
---|
| 138 | #if CONFIG_SHOW_CPU_USAGE |
---|
| 139 | printk(INFO, "INFO: core %d in cluster %x : busy_percent = %d / cumulated_usage = %d\n", |
---|
| 140 | core->lid, local_cxy , busy_percent , usage ); |
---|
| 141 | #endif |
---|
| 142 | |
---|
| 143 | core->ticks_nr = 0; |
---|
| 144 | idle->ticks_nr = 0; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | ///////////////////////////////////// |
---|
| 148 | void core_reset_stats( core_t * core ) |
---|
| 149 | { |
---|
| 150 | core->ticks_nr = 0; |
---|
| 151 | core->usage = 0; |
---|
| 152 | core->thread_idle->ticks_nr = 0; |
---|
[124] | 153 | hal_fence(); |
---|
[1] | 154 | } |
---|
| 155 | |
---|