Skip to content

Commit

Permalink
BHYVE: OS-6633 want cyclic_move_here
Browse files Browse the repository at this point in the history
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: John Levon <john.levon@joyent.com>
  • Loading branch information
pfmooney authored and citrus-it committed Mar 15, 2018
1 parent 62ef589 commit 46bd221
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 57 additions & 1 deletion usr/src/uts/common/os/cyclic.c
Expand Up @@ -24,7 +24,7 @@
*/

/*
* Copyright (c) 2012, Joyent Inc. All rights reserved.
* Copyright 2018 Joyent Inc.
*/

/*
Expand Down Expand Up @@ -112,6 +112,7 @@
* cyclic_remove() <-- Removes a cyclic
* cyclic_bind() <-- Change a cyclic's CPU or partition binding
* cyclic_reprogram() <-- Reprogram a cyclic's expiration
* cyclic_move_here() <-- Shuffle cyclic to current CPU
*
* Inter-subsystem Interfaces
*
Expand Down Expand Up @@ -3111,6 +3112,61 @@ cyclic_reprogram(cyclic_id_t id, hrtime_t expiration)
return (1);
}

/*
* void cyclic_move_here(cyclic_id_t)
*
* Overview
*
* cyclic_move_here() attempts to shuffle a cyclic onto the current CPU.
*
* Arguments and notes
*
* The first argument is a cyclic_id returned from cyclic_add().
* cyclic_move_here() may _not_ be called on a cyclic_id returned from
* cyclic_add_omni() or one bound to a CPU or partition via cyclic_bind().
*
* This cyclic shuffling is performed on a best-effort basis. If for some
* reason the current CPU is unsuitable or the thread migrates between CPUs
* during the call, the function may return with the cyclic residing on some
* other CPU.
*
* Return value
*
* None; cyclic_move_here() always reports success.
*
* Caller's context
*
* cpu_lock must be held by the caller, and the caller must not be in
* interrupt context. The caller may not hold any locks which are also
* grabbed by any cyclic handler.
*/
void
cyclic_move_here(cyclic_id_t id)
{
cyc_id_t *idp = (cyc_id_t *)id;
cyc_cpu_t *cc = idp->cyi_cpu;
cpu_t *dest = CPU;

ASSERT(MUTEX_HELD(&cpu_lock));
CYC_PTRACE("move_here", idp, dest);
VERIFY3P(cc, !=, NULL);
VERIFY3U(cc->cyp_cyclics[idp->cyi_ndx].cy_flags &
(CYF_CPU_BOUND|CYF_PART_BOUND), ==, 0);

if (cc->cyp_cpu == dest) {
return;
}

/* Is the destination CPU suitable for a migration target? */
if (dest->cpu_cyclic == NULL ||
dest->cpu_cyclic->cyp_state == CYS_OFFLINE ||
(dest->cpu_flags & CPU_ENABLE) == 0) {
return;
}

cyclic_juggle_one_to(idp, dest->cpu_cyclic);
}

hrtime_t
cyclic_getres()
{
Expand Down
2 changes: 2 additions & 0 deletions usr/src/uts/common/sys/cyclic.h
Expand Up @@ -23,6 +23,7 @@
* Use is subject to license terms.
*
* Copyright 2017 RackTop Systems.
* Copyright 2018 Joyent, Inc.
*/

#ifndef _SYS_CYCLIC_H
Expand Down Expand Up @@ -81,6 +82,7 @@ extern cyclic_id_t cyclic_add_omni(cyc_omni_handler_t *);
extern void cyclic_remove(cyclic_id_t);
extern void cyclic_bind(cyclic_id_t, cpu_t *, cpupart_t *);
extern int cyclic_reprogram(cyclic_id_t, hrtime_t);
extern void cyclic_move_here(cyclic_id_t);
extern hrtime_t cyclic_getres();

extern int cyclic_offline(cpu_t *cpu);
Expand Down

0 comments on commit 46bd221

Please sign in to comment.