[1] | 1 | /* |
---|
| 2 | * core.h - core descriptor and associated access functions définition |
---|
[19] | 3 | * |
---|
[1] | 4 | * Authors 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 | |
---|
| 25 | #ifndef _CORE_H_ |
---|
| 26 | #define _CORE_H_ |
---|
| 27 | |
---|
[14] | 28 | #include <kernel_config.h> |
---|
[457] | 29 | #include <hal_kernel_types.h> |
---|
[669] | 30 | #include <busylock.h> |
---|
[1] | 31 | #include <list.h> |
---|
| 32 | #include <rpc.h> |
---|
| 33 | #include <scheduler.h> |
---|
| 34 | |
---|
| 35 | /**** Forward declarations ****/ |
---|
| 36 | |
---|
| 37 | struct thread_s; |
---|
[5] | 38 | struct chdev_s; |
---|
[1] | 39 | |
---|
| 40 | /**************************************************************************************** |
---|
[683] | 41 | * This structure defines a core descriptor. |
---|
| 42 | * Besides the core identifiers (gid,lid), it contains an embedded private scheduler |
---|
| 43 | * and a software cycles counter on 64 bits. |
---|
| 44 | * It contains also the root of local list of alarms, dynamically registered by the |
---|
| 45 | * threads running on this core. This local list is protected by a remote_busylock, |
---|
| 46 | * because it can be accessed by any thread, running in any cluster, and using the |
---|
| 47 | * access functions defined in the <alarm.c> & <alarm.h> files. |
---|
[188] | 48 | * It contains an architecture specific extension to store the interrupt vector(s). |
---|
| 49 | * The core_init()function must allocate memory for this extension, depending on the |
---|
| 50 | * PIC device implementation type. |
---|
[1] | 51 | ***************************************************************************************/ |
---|
| 52 | |
---|
| 53 | typedef struct core_s |
---|
| 54 | { |
---|
| 55 | lid_t lid; /*! core local index in cluster */ |
---|
[19] | 56 | gid_t gid; /*! core global identifier (hardware index) */ |
---|
[367] | 57 | |
---|
[683] | 58 | scheduler_t scheduler; /*! embedded private scheduler */ |
---|
| 59 | |
---|
[1] | 60 | uint64_t cycles; /*! total number of cycles (from hard reset) */ |
---|
| 61 | uint32_t time_stamp; /*! previous time stamp (read from register) */ |
---|
[367] | 62 | |
---|
[669] | 63 | list_entry_t alarms_root; /*! root of list of attached alarms */ |
---|
[683] | 64 | remote_busylock_t alarms_lock; /*! lock protecting the list of alarms */ |
---|
[669] | 65 | |
---|
[1] | 66 | uint32_t ticks_nr; /*! number of elapsed ticks */ |
---|
| 67 | uint32_t usage; /*! cumulated busy_percent (idle / total) */ |
---|
[19] | 68 | struct thread_s * fpu_owner; /*! pointer on current FPU owner thread */ |
---|
[1] | 69 | uint32_t rand_last; /*! last computed random value */ |
---|
[409] | 70 | |
---|
[188] | 71 | void * pic_extend; /*! PIC implementation specific extension */ |
---|
[19] | 72 | } |
---|
[1] | 73 | core_t; |
---|
| 74 | |
---|
| 75 | /*************************************************************************************** |
---|
[188] | 76 | * This function initializes a core descriptor. |
---|
[1] | 77 | * It makes the association [gid] <=> [lid], as defined in arch_info, via the |
---|
| 78 | * boot_info_t structure build by the bootloader in each cluster. |
---|
[669] | 79 | * It initializes the core scheduler structures, and the alarms list and lock. |
---|
| 80 | * It allocates memory for the PIC infrastructure specific core extension, |
---|
| 81 | * but it does NOT initialize the <pic_extend> fields, that must be completed later. |
---|
[1] | 82 | *************************************************************************************** |
---|
| 83 | * @ core : pointer on core descriptor to initialise. |
---|
[188] | 84 | * @ lid : local core index in cluster. |
---|
| 85 | * @ gid : global core identifier (hardware index). |
---|
[1] | 86 | **************************************************************************************/ |
---|
[188] | 87 | void core_init( core_t * core, |
---|
| 88 | lid_t lid, |
---|
| 89 | gid_t gid ); |
---|
[1] | 90 | |
---|
| 91 | /*************************************************************************************** |
---|
[657] | 92 | * This function returns the calling core local index (lid), making an associative |
---|
[669] | 93 | * search in the local core_tbl[] array, based on the hardwired (gid). |
---|
[657] | 94 | *************************************************************************************** |
---|
| 95 | * @ returns always the lid value. |
---|
| 96 | **************************************************************************************/ |
---|
| 97 | lid_t core_lid( void ); |
---|
| 98 | |
---|
| 99 | /*************************************************************************************** |
---|
[1] | 100 | * This function returns a pseudo random number from the core descriptor |
---|
| 101 | * private random generator. |
---|
| 102 | *************************************************************************************** |
---|
| 103 | * @ core : pointer on core descriptor. |
---|
| 104 | * @ returns the pseudo random value. |
---|
| 105 | **************************************************************************************/ |
---|
| 106 | inline uint32_t core_get_rand( core_t * core ); |
---|
| 107 | |
---|
| 108 | /*************************************************************************************** |
---|
[101] | 109 | * This function returns the current date (seconds & micro-seconds) from |
---|
| 110 | * the 64 bits calling core cycles counter. |
---|
[1] | 111 | *************************************************************************************** |
---|
| 112 | * @ core : pointer on core descriptor. |
---|
| 113 | * @ tm_s : number of seconds. |
---|
| 114 | * @ tm_us : number of micro-seconds. |
---|
| 115 | **************************************************************************************/ |
---|
| 116 | void core_get_time( core_t * core, |
---|
| 117 | uint32_t * tm_s, |
---|
| 118 | uint32_t * tm_us ); |
---|
| 119 | |
---|
| 120 | /*************************************************************************************** |
---|
| 121 | * This function must be called at each TICK. |
---|
[669] | 122 | * - it updates the ticks counter in the calling core descriptor. |
---|
| 123 | * - it checks the registered alarms depending on the ticks counter value. |
---|
| 124 | * - it calls the scheduler, depending on the ticks counter value. |
---|
[1] | 125 | *************************************************************************************** |
---|
| 126 | * @ core : pointer on core descriptor. |
---|
| 127 | **************************************************************************************/ |
---|
| 128 | void core_clock( core_t * core ); |
---|
| 129 | |
---|
| 130 | /*************************************************************************************** |
---|
[19] | 131 | * This function updates the usage statistics for the calling core descriptor, |
---|
[1] | 132 | * based on the ratio between the idle_ticks and total_ticks. |
---|
| 133 | *************************************************************************************** |
---|
| 134 | * @ core : pointer on core descriptor. |
---|
| 135 | **************************************************************************************/ |
---|
| 136 | void core_compute_stats( core_t * core ); |
---|
| 137 | |
---|
| 138 | /*************************************************************************************** |
---|
[16] | 139 | * This function reset the usage statistics. |
---|
[1] | 140 | *************************************************************************************** |
---|
| 141 | * @ core : pointer on core descriptor. |
---|
| 142 | **************************************************************************************/ |
---|
| 143 | void core_reset_stats( core_t * core ); |
---|
| 144 | |
---|
| 145 | /*************************************************************************************** |
---|
| 146 | * This function set/reset a selected entry in one interrupt vector for a remote core. |
---|
| 147 | * The written value is an extended pointer on the "source" device (or the XPTR_NULL |
---|
[19] | 148 | * value in case of reset). As it uses remote access, this function can be called by |
---|
[1] | 149 | * any thread in any cluster. |
---|
| 150 | *************************************************************************************** |
---|
[5] | 151 | * @ core : local pointer on the core descriptor. |
---|
[1] | 152 | * @ irq_type : type of IRQ (HWI/WTI/PTI). |
---|
| 153 | * @ irq_id : index in the IRQ vector. |
---|
[5] | 154 | * @ chdev : local pointer on the "source" chdev descriptor. |
---|
[1] | 155 | **************************************************************************************/ |
---|
[5] | 156 | void core_set_irq_vector_entry( core_t * core, |
---|
| 157 | uint32_t irq_type, |
---|
| 158 | uint32_t irq_id, |
---|
| 159 | struct chdev_s * chdev ); |
---|
[1] | 160 | |
---|
| 161 | |
---|
| 162 | #endif /* _CORE_H_ */ |
---|