Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ For example, you can do:
ln -s $H mq
```

The mq scripts are dependent on the [`jq`](https://jqlang.org/download/) and
[`machine-locks-client`](https://github.com/au-ts/machine-locks/tree/main/machine_locks_client).
Follow the instructions at each of those links to download or compile them, and
add them to your `$PATH`.

The mq scripts assume a standard POSIX system, that `/bin/sh` is
POSIX compliant, and that you can use `ssh` to reach
`tftp.keg.cse.unsw.edu.au` without password. To set up the latter,
Expand All @@ -49,6 +54,16 @@ or clauses with similar effect. The script makes many `ssh`
connections in a row; without the control multiplexing this can get
painfully slow.

Usage with Nix
================

You will need to enable the Nix 'flakes' feature. Then spawn a shell with:
```
nix shell github:seL4/machine_queue
```
Then, all `mq` dependencies will be accessible to `mq` automatically, and `mq.sh`
will be in your `$PATH`. You do not need to clone the repo or set up any symlinks.
You will still need to setup an appropriate SSH config.

Usage
======
Expand Down Expand Up @@ -97,29 +112,12 @@ Options:
- `-t` _RETRIES_ Number of retries to perform for acquiring the lock (default -1)
- `--bitstream` _FILE_ Optional bitstream file to load to the FPGA.

`mq sem dumpall|info|acquire|release|help [`_options_`]`

`mq sem dumpall|-signal|-wait|-cancel|-info `_<system>_` [-f] [-w `_retry-time_` ] [-t `_retry-count_` ] [-k `_LOCK_\__KEY_` ] [-T` _timeout_`]`

Manually manipulate locks for machines. The lock for each system
can be acquired or released.

You can forcibly release a lock for a system that you do not
currently own by using the `-f` flag

Options:

- `-info` _SYSTEM_ Display lock information for the specified SYSTEM
- `-mr-info` _SYSTEM_ Display lock information for the specified SYSTEM in machine-readable format
- `-signal` _SYSTEM_ Release the lock for the specified SYSTEM
- `-wait` _SYSTEM_ Acquire the lock for the specified SYSTEM
- `-cancel` _SYSTEM_ Cancel `-wait` processes on the server that are waiting for specified SYSTEM and key
- `-w` _TIME_ Number of seconds to wait between each attempt to acquire the lock (default 8)
- `-t` _RETRIES_ Number of retries to perform for acquiring the
lock (default -1, which means infinity)
- `-f` Forcefully releases a lock even if you are not the owner
- `-k` _LOCK\_KEY_ Set a key inside the lock
- `-T` _timeout_ Allow lock to be reclaimed after _timeout_ seconds
- `dumpall` Prints all currently locked systems
Manually manipulate locks for machines. The lock for each system can be acquired
or released. This is a pass-through to `machine-locks-client sem ...`, read its
documentation
[here](https://github.com/au-ts/machine-locks/tree/main/machine_locks_client).

`mq systems [help|simple]`

Expand Down
56 changes: 56 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
description = "Machine Queue scripts for remote access to our CI system";

inputs = {
nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst";
machine-locks.url = "github:au-ts/machine-locks";
};

outputs =
inputs:
let
deps = system: pkgs: [
inputs.machine-locks.packages.${system}.client
pkgs.jq
];
in
{
devShells = builtins.mapAttrs (system: pkgs: {
default = pkgs.mkShell {
packages = deps system pkgs;
};
}) inputs.nixpkgs.legacyPackages;
packages = builtins.mapAttrs (system: pkgs: {
default = pkgs.stdenv.mkDerivation {
pname = "machine_queue";
version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION);
src = ./.;

nativeBuildInputs = [ pkgs.makeWrapper ];

installPhase = ''
runHook preInstall

mkdir -p $out/bin
cp -r mq.sh scripts $out/bin/

wrapProgram $out/bin/mq.sh \
--prefix PATH : ${pkgs.lib.makeBinPath (deps system pkgs)}

runHook postInstall
'';
};
}) inputs.nixpkgs.legacyPackages;
};
}
5 changes: 2 additions & 3 deletions mq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ case "$command" in
exit 1
;;
sem)
UserLock "$@"
# Should not get here
exit 1
machine-locks-client sem "$@"
exit
;;
help|*)
Usage
Expand Down
26 changes: 14 additions & 12 deletions scripts/enqueue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright 2021 UNSW, Sydney
# Copyright 2026 UNSW, Sydney
#
# SPDX-License-Identifier: GPL-2.0-only

Expand Down Expand Up @@ -49,8 +49,7 @@ EnqueueUsage() {
Enqueue() {
# Parse the command line
file_count=0
retry_period=8
total_retries=-1
total_retries=""
logfile=""
interact=""
no_lock_mods=false
Expand Down Expand Up @@ -137,10 +136,6 @@ Enqueue() {
shift
key="$1"
;;
-w)
shift
retry_period="$1"
;;
-t)
shift
total_retries="$1"
Expand Down Expand Up @@ -216,23 +211,30 @@ Enqueue() {
fi

if ${no_lock_mods} ; then
# replace
if ! LockIOwn "${system}"; then
echo "Failed to run because you said you own the lock (-n flag), but you don't!"
LockSystemPrintInfo "${system}"
machine-locks-client sem info "${system}"
exit 1
fi
else
echo "Acquiring lock for ${system}"

# Print out potentially useful information to the user about
# the current status of the lock
LockSystemPrintInfo "${system}"
machine-locks-client sem info "${system}"

# We can setup the trap early as we check if we actually own the
# the lock before releasing it
trap "UnlockSystem \"${system}\" 0 \"${key}\"; exit 1" ${SIGNALS}
# replace
trap "machine-locks-client sem release --owner "$REMOTEUSER" "$system"; exit 1" ${SIGNALS}

if ! LockSystem "${system}" "${retry_period}" "${total_retries}" "${key}"; then
if ! machine-locks-client sem acquire \
--owner "$REMOTEUSER" \
${total_retries:+--num-retries $total_retries} \
${timeout:+--timeout $timeout} \
${key:+--job-name "$key"} \
"$system"; then
echo "Failed to acquire lock for system (${system})"
exit 2
fi
Expand Down Expand Up @@ -260,7 +262,7 @@ Enqueue() {
fi

if ! ${no_lock_mods} ; then
UnlockSystem "${system}" 0 "${key}"
machine-locks-client sem release --owner "$REMOTEUSER" "$system"
trap "exit 1" ${SIGNALS}
fi

Expand Down
Loading