int migrator_loop() { task_register_cons *trc; while (1) { vTaskDelay(1000/portTICK_RATE_MS); if ((trc = task_find("rtuapp"))) { if (!task_wait_for_checkpoint(trc, cp_req_rtu)) { ERROR_MSG("%s: Failed to reach rtu checkpoint for task \"%s\"\n", __func__, trc->name); return 0; } Elf32_Ehdr *new_sw = (Elf32_Ehdr *)&_rtuappv2_elf_start; INFO_MSG("Starting runtime update.\n"); if (!migrator_runtime_update(trc, new_sw)) { ERROR_MSG("Runtime updating failed.\n"); return 0; } INFO_MSG("Runtime update complete. (-> v2)\n"); } vTaskDelay(1000/portTICK_RATE_MS); if ((trc = task_find("rtuapp"))) { if (!task_wait_for_checkpoint(trc, cp_req_rtu)) { ERROR_MSG("%s: Failed to reach rtu checkpoint for task \"%s\"\n", __func__, trc->name); return 0; } Elf32_Ehdr *new_sw = (Elf32_Ehdr *)&_rtuappv1_elf_start; INFO_MSG("Starting runtime update.\n"); if (!migrator_runtime_update(trc, new_sw)) { ERROR_MSG("Runtime updating failed.\n"); return 0; } INFO_MSG("Runtime update complete. (-> v1)\n"); } } }
/* * task_hold_by_id(), task_hold_by_id_zone() * * Overview * task_hold_by_id() is used to take a reference on a task by its task id, * supporting the various system call interfaces for obtaining resource data, * delivering signals, and so forth. * * Return values * Returns a pointer to the task_t with taskid_t id. The task is returned * with its hold count incremented by one. Returns NULL if there * is no task with the requested id. * * Caller's context * Caller must not be holding task_hash_lock. No restrictions on context. */ task_t * task_hold_by_id_zone(taskid_t id, zoneid_t zoneid) { task_t *tk; mutex_enter(&task_hash_lock); if ((tk = task_find(id, zoneid)) != NULL) atomic_inc_32(&tk->tk_hold_count); mutex_exit(&task_hash_lock); return (tk); }
int effect_start_and_config (const char *new_task_name, const char *binary_name, binary_register_entry *bre, u_int16_t init_width, u_int16_t init_height, u_int16_t init_w_offset, u_int16_t init_h_offset) { if (!alloc_link_start_from_binary_register(new_task_name, binary_name, bre)) { return 0; } task_register_cons *trc = task_find(new_task_name); if (trc == NULL) { return 0; } return effect_config(trc, init_width, init_height, init_w_offset, init_h_offset); }
/* * void task_init(void) * * Overview * task_init() initializes task-related hashes, caches, and the task id * space. Additionally, task_init() establishes p0 as a member of task0. * Called by main(). * * Return values * None. * * Caller's context * task_init() must be called prior to MP startup. */ void task_init(void) { proc_t *p = &p0; mod_hash_hndl_t hndl; rctl_set_t *set; rctl_alloc_gp_t *gp; rctl_entity_p_t e; /* * Initialize task_cache and taskid_space. */ task_cache = kmem_cache_create("task_cache", sizeof (task_t), 0, NULL, NULL, NULL, NULL, NULL, 0); taskid_space = id_space_create("taskid_space", 0, MAX_TASKID); /* * Initialize task hash table. */ task_hash = mod_hash_create_idhash("task_hash", task_hash_size, mod_hash_null_valdtor); /* * Initialize task-based rctls. */ rc_task_lwps = rctl_register("task.max-lwps", RCENTITY_TASK, RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_COUNT, INT_MAX, INT_MAX, &task_lwps_ops); rc_task_nprocs = rctl_register("task.max-processes", RCENTITY_TASK, RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_COUNT, INT_MAX, INT_MAX, &task_procs_ops); rc_task_cpu_time = rctl_register("task.max-cpu-time", RCENTITY_TASK, RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_DENY_NEVER | RCTL_GLOBAL_CPU_TIME | RCTL_GLOBAL_INFINITE | RCTL_GLOBAL_UNOBSERVABLE | RCTL_GLOBAL_SECONDS, UINT64_MAX, UINT64_MAX, &task_cpu_time_ops); /* * Create task0 and place p0 in it as a member. */ task0p = kmem_cache_alloc(task_cache, KM_SLEEP); bzero(task0p, sizeof (task_t)); task0p->tk_tkid = id_alloc(taskid_space); task0p->tk_usage = kmem_zalloc(sizeof (task_usage_t), KM_SLEEP); task0p->tk_inherited = kmem_zalloc(sizeof (task_usage_t), KM_SLEEP); task0p->tk_proj = project_hold_by_id(0, &zone0, PROJECT_HOLD_INSERT); task0p->tk_flags = TASK_NORMAL; task0p->tk_nlwps = p->p_lwpcnt; task0p->tk_nprocs = 1; task0p->tk_zone = global_zone; task0p->tk_commit_next = NULL; set = rctl_set_create(); gp = rctl_set_init_prealloc(RCENTITY_TASK); mutex_enter(&curproc->p_lock); e.rcep_p.task = task0p; e.rcep_t = RCENTITY_TASK; task0p->tk_rctls = rctl_set_init(RCENTITY_TASK, curproc, &e, set, gp); mutex_exit(&curproc->p_lock); rctl_prealloc_destroy(gp); (void) mod_hash_reserve(task_hash, &hndl); mutex_enter(&task_hash_lock); ASSERT(task_find(task0p->tk_tkid, GLOBAL_ZONEID) == NULL); if (mod_hash_insert_reserve(task_hash, (mod_hash_key_t)(uintptr_t)task0p->tk_tkid, (mod_hash_val_t *)task0p, hndl) != 0) { mod_hash_cancel(task_hash, &hndl); panic("unable to insert task %d(%p)", task0p->tk_tkid, (void *)task0p); } mutex_exit(&task_hash_lock); task0p->tk_memb_list = p; task0p->tk_nprocs_kstat = task_kstat_create(task0p, task0p->tk_zone); /* * Initialize task pointers for p0, including doubly linked list of task * members. */ p->p_task = task0p; p->p_taskprev = p->p_tasknext = p; task_hold(task0p); }
/* * task_t *task_create(projid_t, zone *) * * Overview * A process constructing a new task calls task_create() to construct and * preinitialize the task for the appropriate destination project. Only one * task, the primordial task0, is not created with task_create(). * * Return values * None. * * Caller's context * Caller's context should be safe for KM_SLEEP allocations. * The caller should appropriately bump the kpj_ntasks counter on the * project that contains this task. */ task_t * task_create(projid_t projid, zone_t *zone) { task_t *tk = kmem_cache_alloc(task_cache, KM_SLEEP); task_t *ancestor_tk; taskid_t tkid; task_usage_t *tu = kmem_zalloc(sizeof (task_usage_t), KM_SLEEP); mod_hash_hndl_t hndl; rctl_set_t *set = rctl_set_create(); rctl_alloc_gp_t *gp; rctl_entity_p_t e; bzero(tk, sizeof (task_t)); tk->tk_tkid = tkid = id_alloc(taskid_space); tk->tk_nlwps = 0; tk->tk_nlwps_ctl = INT_MAX; tk->tk_nprocs = 0; tk->tk_nprocs_ctl = INT_MAX; tk->tk_usage = tu; tk->tk_inherited = kmem_zalloc(sizeof (task_usage_t), KM_SLEEP); tk->tk_proj = project_hold_by_id(projid, zone, PROJECT_HOLD_INSERT); tk->tk_flags = TASK_NORMAL; tk->tk_commit_next = NULL; /* * Copy ancestor task's resource controls. */ zone_task_hold(zone); mutex_enter(&curproc->p_lock); ancestor_tk = curproc->p_task; task_hold(ancestor_tk); tk->tk_zone = zone; mutex_exit(&curproc->p_lock); for (;;) { gp = rctl_set_dup_prealloc(ancestor_tk->tk_rctls); mutex_enter(&ancestor_tk->tk_rctls->rcs_lock); if (rctl_set_dup_ready(ancestor_tk->tk_rctls, gp)) break; mutex_exit(&ancestor_tk->tk_rctls->rcs_lock); rctl_prealloc_destroy(gp); } /* * At this point, curproc does not have the appropriate linkage * through the task to the project. So, rctl_set_dup should only * copy the rctls, and leave the callbacks for later. */ e.rcep_p.task = tk; e.rcep_t = RCENTITY_TASK; tk->tk_rctls = rctl_set_dup(ancestor_tk->tk_rctls, curproc, curproc, &e, set, gp, RCD_DUP); mutex_exit(&ancestor_tk->tk_rctls->rcs_lock); rctl_prealloc_destroy(gp); /* * Record the ancestor task's ID for use by extended accounting. */ tu->tu_anctaskid = ancestor_tk->tk_tkid; task_rele(ancestor_tk); /* * Put new task structure in the hash table. */ (void) mod_hash_reserve(task_hash, &hndl); mutex_enter(&task_hash_lock); ASSERT(task_find(tkid, zone->zone_id) == NULL); if (mod_hash_insert_reserve(task_hash, (mod_hash_key_t)(uintptr_t)tkid, (mod_hash_val_t *)tk, hndl) != 0) { mod_hash_cancel(task_hash, &hndl); panic("unable to insert task %d(%p)", tkid, (void *)tk); } mutex_exit(&task_hash_lock); tk->tk_nprocs_kstat = task_kstat_create(tk, zone); return (tk); }