[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) |
---|
| 5 | * Mohamed Lamine Karaoui (2015) |
---|
| 6 | * Alain Greiner (2016) |
---|
| 7 | * |
---|
| 8 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 9 | * |
---|
| 10 | * This file is part of ALMOS-MKH. |
---|
| 11 | * |
---|
| 12 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 13 | * under the terms of the GNU General Public License as published by |
---|
| 14 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 15 | * |
---|
| 16 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 19 | * General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 23 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #ifndef _CORE_H_ |
---|
| 27 | #define _CORE_H_ |
---|
| 28 | |
---|
[14] | 29 | #include <kernel_config.h> |
---|
[1] | 30 | #include <hal_types.h> |
---|
| 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 | |
---|
| 41 | /**************************************************************************************** |
---|
[5] | 42 | * This structure defines the core descriptor. |
---|
[14] | 43 | * - It contains an embedded private scheduler. |
---|
| 44 | * - It contains the three interrupt vectors, implemented as three arrays of pointers |
---|
| 45 | * on the source channel devices, for all IRQs allocated to the core. |
---|
[1] | 46 | ***************************************************************************************/ |
---|
| 47 | |
---|
| 48 | typedef struct core_s |
---|
| 49 | { |
---|
| 50 | lid_t lid; /*! core local index in cluster */ |
---|
[19] | 51 | gid_t gid; /*! core global identifier (hardware index) */ |
---|
[1] | 52 | uint64_t cycles; /*! total number of cycles (from hard reset) */ |
---|
| 53 | uint32_t time_stamp; /*! previous time stamp (read from register) */ |
---|
| 54 | uint32_t ticks_nr; /*! number of elapsed ticks */ |
---|
| 55 | uint32_t ticks_period; /*! number of cycles between two ticks */ |
---|
| 56 | uint32_t usage; /*! cumulated busy_percent (idle / total) */ |
---|
| 57 | uint32_t spurious_irqs; /*! for instrumentation... */ |
---|
| 58 | struct thread_s * thread_rpc; /*! pointer on current RPC thread descriptor */ |
---|
| 59 | struct thread_s * thread_idle; /*! pointer on idle thread descriptor */ |
---|
[19] | 60 | struct thread_s * fpu_owner; /*! pointer on current FPU owner thread */ |
---|
[1] | 61 | uint32_t rand_last; /*! last computed random value */ |
---|
| 62 | uint32_t rpc_threads; /*! total number of RPC threads for this core */ |
---|
| 63 | list_entry_t rpc_free_list; /*! root of the list of free RPC threads */ |
---|
| 64 | rpc_fifo_t rpc_fifo; /*! embedded private RPC fifo (one per core) */ |
---|
[14] | 65 | |
---|
[1] | 66 | scheduler_t scheduler; /*! embedded private scheduler */ |
---|
| 67 | |
---|
[5] | 68 | struct chdev_s * hwi_vector[CONFIG_MAX_HWIS_PER_ICU]; /*! on source device */ |
---|
| 69 | struct chdev_s * pti_vector[CONFIG_MAX_PTIS_PER_ICU]; /*! on source device */ |
---|
| 70 | struct chdev_s * wti_vector[CONFIG_MAX_WTIS_PER_ICU]; /*! on source device */ |
---|
[1] | 71 | |
---|
[14] | 72 | // sysfs_entry_t node; |
---|
[19] | 73 | } |
---|
[1] | 74 | core_t; |
---|
| 75 | |
---|
| 76 | /*************************************************************************************** |
---|
| 77 | * This macro returns a pointer on the calling core descriptor. |
---|
| 78 | **************************************************************************************/ |
---|
| 79 | |
---|
| 80 | #define CURRENT_CORE (CURRENT_THREAD->core) |
---|
| 81 | |
---|
| 82 | /*************************************************************************************** |
---|
| 83 | * TODO this initialisation must be completed for the thread_idle field... [AG] |
---|
| 84 | * This function initializes a core descriptor from information found in arch_info. |
---|
| 85 | * It makes the association [gid] <=> [lid], as defined in arch_info, via the |
---|
| 86 | * boot_info_t structure build by the bootloader in each cluster. |
---|
| 87 | *************************************************************************************** |
---|
| 88 | * @ core : pointer on core descriptor to initialise. |
---|
[19] | 89 | * @ lid : local core index |
---|
[1] | 90 | * @ gid : global core identifier (hardware index) |
---|
| 91 | **************************************************************************************/ |
---|
[19] | 92 | void core_init( core_t * core, |
---|
| 93 | lid_t lid, |
---|
[1] | 94 | gid_t gid ); |
---|
| 95 | |
---|
| 96 | /*************************************************************************************** |
---|
| 97 | * This function returns a pseudo random number from the core descriptor |
---|
| 98 | * private random generator. |
---|
| 99 | *************************************************************************************** |
---|
| 100 | * @ core : pointer on core descriptor. |
---|
| 101 | * @ returns the pseudo random value. |
---|
| 102 | **************************************************************************************/ |
---|
| 103 | inline uint32_t core_get_rand( core_t * core ); |
---|
| 104 | |
---|
| 105 | /*************************************************************************************** |
---|
[19] | 106 | * This function returns the current date (cycles) from both |
---|
| 107 | * the hardware 32 bits cycles counter and the core descriptor cycles counter, |
---|
[1] | 108 | * taking into account the 32 bits hardware register overflow. |
---|
| 109 | * The core descriptor time is updated. |
---|
| 110 | *************************************************************************************** |
---|
| 111 | * @ core : pointer on core descriptor. |
---|
| 112 | * @ returns the number of cycles. |
---|
| 113 | **************************************************************************************/ |
---|
| 114 | inline uint64_t core_get_cycles( core_t * core ); |
---|
| 115 | |
---|
| 116 | /*************************************************************************************** |
---|
| 117 | * This function returns the current date (seconds & micro-seconds) from both |
---|
[19] | 118 | * the hardware 32 bits cycles counter and the core descriptor cycles counter, |
---|
[1] | 119 | * taking into account the 32 bits hardware register overflow. |
---|
| 120 | * The core descriptor time is updated. |
---|
| 121 | *************************************************************************************** |
---|
| 122 | * @ core : pointer on core descriptor. |
---|
| 123 | * @ tm_s : number of seconds. |
---|
| 124 | * @ tm_us : number of micro-seconds. |
---|
| 125 | **************************************************************************************/ |
---|
| 126 | void core_get_time( core_t * core, |
---|
| 127 | uint32_t * tm_s, |
---|
| 128 | uint32_t * tm_us ); |
---|
| 129 | |
---|
| 130 | /*************************************************************************************** |
---|
| 131 | * This function must be called at each TICK. |
---|
| 132 | * It updates the cycles and ticks counter in the calling core descriptor. |
---|
| 133 | * It handles all pending alarms depending on the ticks counter value. |
---|
[19] | 134 | * It handles the scheduling, depending on the ticks counter value. |
---|
[1] | 135 | * It handles the global DQDT update, depending on the ticks counter vakue. |
---|
| 136 | *************************************************************************************** |
---|
| 137 | * @ core : pointer on core descriptor. |
---|
| 138 | **************************************************************************************/ |
---|
| 139 | void core_clock( core_t * core ); |
---|
| 140 | |
---|
| 141 | /*************************************************************************************** |
---|
[19] | 142 | * This function updates the usage statistics for the calling core descriptor, |
---|
[1] | 143 | * based on the ratio between the idle_ticks and total_ticks. |
---|
| 144 | *************************************************************************************** |
---|
| 145 | * @ core : pointer on core descriptor. |
---|
| 146 | **************************************************************************************/ |
---|
| 147 | void core_compute_stats( core_t * core ); |
---|
| 148 | |
---|
| 149 | /*************************************************************************************** |
---|
[16] | 150 | * This function reset the usage statistics. |
---|
[1] | 151 | *************************************************************************************** |
---|
| 152 | * @ core : pointer on core descriptor. |
---|
| 153 | **************************************************************************************/ |
---|
| 154 | void core_reset_stats( core_t * core ); |
---|
| 155 | |
---|
| 156 | /*************************************************************************************** |
---|
| 157 | * This function set/reset a selected entry in one interrupt vector for a remote core. |
---|
| 158 | * The written value is an extended pointer on the "source" device (or the XPTR_NULL |
---|
[19] | 159 | * value in case of reset). As it uses remote access, this function can be called by |
---|
[1] | 160 | * any thread in any cluster. |
---|
| 161 | *************************************************************************************** |
---|
[5] | 162 | * @ core : local pointer on the core descriptor. |
---|
[1] | 163 | * @ irq_type : type of IRQ (HWI/WTI/PTI). |
---|
| 164 | * @ irq_id : index in the IRQ vector. |
---|
[5] | 165 | * @ chdev : local pointer on the "source" chdev descriptor. |
---|
[1] | 166 | **************************************************************************************/ |
---|
[5] | 167 | void core_set_irq_vector_entry( core_t * core, |
---|
| 168 | uint32_t irq_type, |
---|
| 169 | uint32_t irq_id, |
---|
| 170 | struct chdev_s * chdev ); |
---|
[1] | 171 | |
---|
| 172 | |
---|
| 173 | #endif /* _CORE_H_ */ |
---|