target/smp: use a struct list_head to hold the smp targets

Instead of reinventing a simply linked list, reuse the list helper
for the list of targets in a smp cluster.
Using the existing helper, that implements a double linked list,
makes trivial going through the list in reverse order.

Change-Id: Ib36ad2955f15cd2a601b0b9e36ca6d948b12d00f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6783
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2021-12-16 01:59:14 +01:00
parent 5ab74bde06
commit 16cc853bcf
16 changed files with 136 additions and 178 deletions

View File

@@ -56,6 +56,7 @@
#include "rtos/rtos.h"
#include "transport/transport.h"
#include "arm_cti.h"
#include "smp.h"
/* default halt wait timeout (ms) */
#define DEFAULT_HALT_TIMEOUT 5000
@@ -159,6 +160,7 @@ static int64_t target_timer_next_event_value;
static LIST_HEAD(target_reset_callback_list);
static LIST_HEAD(target_trace_callback_list);
static const int polling_interval = TARGET_DEFAULT_POLLING_INTERVAL;
static LIST_HEAD(empty_smp_targets);
static const struct jim_nvp nvp_assert[] = {
{ .name = "assert", NVP_ASSERT },
@@ -2272,13 +2274,15 @@ static void target_destroy(struct target *target)
/* release the targets SMP list */
if (target->smp) {
struct target_list *head = target->head;
while (head) {
struct target_list *pos = head->next;
struct target_list *head, *tmp;
list_for_each_entry_safe(head, tmp, target->smp_targets, lh) {
list_del(&head->lh);
head->target->smp = 0;
free(head);
head = pos;
}
if (target->smp_targets != &empty_smp_targets)
free(target->smp_targets);
target->smp = 0;
}
@@ -5786,6 +5790,9 @@ static int target_create(struct jim_getopt_info *goi)
return JIM_ERR;
}
/* set empty smp cluster */
target->smp_targets = &empty_smp_targets;
/* set target number */
target->target_number = new_target_number();
@@ -5998,9 +6005,7 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
const char *targetname;
int retval, len;
struct target *target = NULL;
struct target_list *head, *curr, *new;
curr = NULL;
head = NULL;
struct target_list *head, *new;
retval = 0;
LOG_DEBUG("%d", argc);
@@ -6009,6 +6014,13 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
* argv[3] ...
*/
struct list_head *lh = malloc(sizeof(*lh));
if (!lh) {
LOG_ERROR("Out of memory");
return JIM_ERR;
}
INIT_LIST_HEAD(lh);
for (i = 1; i < argc; i++) {
targetname = Jim_GetString(argv[i], &len);
@@ -6017,24 +6029,14 @@ static int jim_target_smp(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (target) {
new = malloc(sizeof(struct target_list));
new->target = target;
new->next = NULL;
if (!head) {
head = new;
curr = head;
} else {
curr->next = new;
curr = new;
}
list_add_tail(&new->lh, lh);
}
}
/* now parse the list of cpu and put the target in smp mode*/
curr = head;
while (curr) {
target = curr->target;
foreach_smp_target(head, lh) {
target = head->target;
target->smp = 1;
target->head = head;
curr = curr->next;
target->smp_targets = lh;
}
if (target && target->rtos)