Changes have been pushed for the repository "fawkesrobotics/fawkes".
Clone: https://github.com/fawkesrobotics/fawkes.git Gitweb: https://github.com/fawkesrobotics/fawkes The branch, thofmann/cx-resource-locking-with-multiple-goals has been created at 1e60e694dd420844574df2b89241c769fae7a456 (commit) https://github.com/fawkesrobotics/fawkes/tree/thofmann/cx-resource-locking-with-multiple-goals - *Log* --------------------------------------------------------------- commit 3e71d6e9749dd1186feae55d4f3c7608b9e49964 Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> AuthorDate: Wed Jun 26 11:35:08 2019 +0200 Commit: Till Hofmann <hofm...@kbsg.rwth-aachen.de> CommitDate: Wed Jun 26 11:35:08 2019 +0200 clips-executive: fix leaked resource in goal fast rejection The rule is supposed to trigger only if there is no mutex with a pending request, because otherwise we need to wait for the response for that request. By re-using the variable name `?n`, which was bound before, we only checked if there is no request for that particular mutex. Fix this by using a different variable name. https://github.com/fawkesrobotics/fawkes/commit/3e71d6e97 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit d966579a24504217dce1860cb1b496093e275ed6 Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> AuthorDate: Wed Jun 26 12:26:17 2019 +0200 Commit: Till Hofmann <hofm...@kbsg.rwth-aachen.de> CommitDate: Wed Jun 26 12:26:26 2019 +0200 clips-executive: reject goal if another goal has a required resource If we have two goals that require the same resource and one of the goals has already acquired a resource, reject the other goal instead of waiting for the first goal to complete. https://github.com/fawkesrobotics/fawkes/commit/d966579a2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 4f9a51a30c96476ec1c37ead91a9c6f4508e8008 Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> AuthorDate: Wed Jun 26 12:31:54 2019 +0200 Commit: Till Hofmann <hofm...@kbsg.rwth-aachen.de> CommitDate: Wed Jun 26 12:31:54 2019 +0200 clips-executive: print error if a resource is locked with unknown reason We expect that a resource is already locked either because someone else locked it, or it is already locked for a different goal. In any other case, print an error. https://github.com/fawkesrobotics/fawkes/commit/4f9a51a30 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 12f7cdb99b7739311d7f039f32f9f6f6ed581ce5 Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> AuthorDate: Wed Jun 26 12:33:37 2019 +0200 Commit: Till Hofmann <hofm...@kbsg.rwth-aachen.de> CommitDate: Wed Jun 26 12:33:37 2019 +0200 clips-executive: only try to get resource if none has been acquired We should try to get all required resources at the same time and only once. https://github.com/fawkesrobotics/fawkes/commit/12f7cdb99 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - commit 1e60e694dd420844574df2b89241c769fae7a456 Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> AuthorDate: Wed Jun 26 13:50:29 2019 +0200 Commit: Till Hofmann <hofm...@kbsg.rwth-aachen.de> CommitDate: Wed Jun 26 13:50:29 2019 +0200 clips-executive: keep track for which goal we requested a resource If we have two goals that require the same resource, we need to keep track for which goal we actually requested the resource. Otherwise, we may request a resource for goal 1 and then assign it to goal 2. This is undesirable, because goal 2 may require additional resources that we have not requested, resulting in a deadlock. On the way, split the rule for fast rejection into two rules, because we can now directly check if another goal requested the same resource. https://github.com/fawkesrobotics/fawkes/commit/1e60e694d - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *Summary* ----------------------------------------------------------- .../clips-executive/clips/resource-locks.clp | 63 ++++++++++++++++------ 1 file changed, 47 insertions(+), 16 deletions(-) - *Diffs* ------------------------------------------------------------- - *commit* 3e71d6e9749dd1186feae55d4f3c7608b9e49964 - - - - - - - - - - Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> Date: Wed Jun 26 11:35:08 2019 +0200 Subject: clips-executive: fix leaked resource in goal fast rejection src/plugins/clips-executive/clips/resource-locks.clp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) _Diff for modified files_: diff --git a/src/plugins/clips-executive/clips/resource-locks.clp b/src/plugins/clips-executive/clips/resource-locks.clp index 231e8b32b..0ae04e348 100644 --- a/src/plugins/clips-executive/clips/resource-locks.clp +++ b/src/plugins/clips-executive/clips/resource-locks.clp @@ -60,7 +60,7 @@ (required-resources $?req)) (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) (state LOCKED) (locked-by ?locker&~?identity)) - (not (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) + (not (mutex (name ?n1&:(member$ (mutex-to-resource ?n1) ?req)) (request ~NONE))) => (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) - *commit* d966579a24504217dce1860cb1b496093e275ed6 - - - - - - - - - - Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> Date: Wed Jun 26 12:26:17 2019 +0200 Subject: clips-executive: reject goal if another goal has a required resource src/plugins/clips-executive/clips/resource-locks.clp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) _Diff for modified files_: diff --git a/src/plugins/clips-executive/clips/resource-locks.clp b/src/plugins/clips-executive/clips/resource-locks.clp index 0ae04e348..4ea467ab3 100644 --- a/src/plugins/clips-executive/clips/resource-locks.clp +++ b/src/plugins/clips-executive/clips/resource-locks.clp @@ -51,20 +51,30 @@ ) (defrule resource-locks-fast-reject-goal - "If a resource is locked by someone else, we have not acquired any resources, - and we have no pending requests, then we can directly reject the goal." + "If a resource already locked, either by someone else or for a different + goal, we have not acquired any resources, and we have no pending requests, + then we can directly reject the goal." (wm-fact (key cx identity) (value ?identity)) ?g <- (goal (mode COMMITTED) (id ?goal-id) (acquired-resources) (required-resources $?req)) + ; The mutex is locked and there is no unprocessed request, which means that + ; it was either locked by someone else or for a different goal. (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) - (state LOCKED) (locked-by ?locker&~?identity)) + (state LOCKED) (request NONE) (locked-by ?locker)) (not (mutex (name ?n1&:(member$ (mutex-to-resource ?n1) ?req)) (request ~NONE))) => - (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) - " is already locked by " ?locker crlf) + (if (neq ?locker ?identity) + (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) + " is already locked by " ?locker crlf) + else + (do-for-fact ((?og goal)) (member$ (mutex-to-resource ?n) ?og:acquired-resources) + (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) + " is already locked for " ?og:id crlf) + ) + ) (modify ?g (mode FINISHED) (outcome REJECTED)) ) - *commit* 4f9a51a30c96476ec1c37ead91a9c6f4508e8008 - - - - - - - - - - Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> Date: Wed Jun 26 12:31:54 2019 +0200 Subject: clips-executive: print error if a resource is locked with unknown reason src/plugins/clips-executive/clips/resource-locks.clp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) _Diff for modified files_: diff --git a/src/plugins/clips-executive/clips/resource-locks.clp b/src/plugins/clips-executive/clips/resource-locks.clp index 4ea467ab3..b78bc3812 100644 --- a/src/plugins/clips-executive/clips/resource-locks.clp +++ b/src/plugins/clips-executive/clips/resource-locks.clp @@ -70,9 +70,15 @@ (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) " is already locked by " ?locker crlf) else - (do-for-fact ((?og goal)) (member$ (mutex-to-resource ?n) ?og:acquired-resources) - (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) - " is already locked for " ?og:id crlf) + (if (not (do-for-fact ((?og goal)) + (member$ (mutex-to-resource ?n) ?og:acquired-resources) + (printout warn "Rejecting goal " ?goal-id ", " + (mutex-to-resource ?n) + " is already locked for " ?og:id crlf))) + then + (printout error "Rejecting goal " ?goal-id ", resource " + (mutex-to-resource ?n) + " is already locked, but could not determine why!" crlf) ) ) (modify ?g (mode FINISHED) (outcome REJECTED)) - *commit* 12f7cdb99b7739311d7f039f32f9f6f6ed581ce5 - - - - - - - - - - Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> Date: Wed Jun 26 12:33:37 2019 +0200 Subject: clips-executive: only try to get resource if none has been acquired src/plugins/clips-executive/clips/resource-locks.clp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) _Diff for modified files_: diff --git a/src/plugins/clips-executive/clips/resource-locks.clp b/src/plugins/clips-executive/clips/resource-locks.clp index b78bc3812..5732e41f3 100644 --- a/src/plugins/clips-executive/clips/resource-locks.clp +++ b/src/plugins/clips-executive/clips/resource-locks.clp @@ -34,17 +34,17 @@ ) (defrule resource-locks-request-lock + "Request a mutex for each required resource if none of the respective mutexes + is already locked or has a pending request." (goal (mode COMMITTED) - (acquired-resources $?acq) - (required-resources $?req)) - ; We may have multiple goals requiring the same resource. If that's the case, - ; wait until the other goal releases the resources. + (acquired-resources) + (required-resources $?req&:(> (length$ ?req) 0))) (not (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) (request ~NONE))) (not (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) (state LOCKED))) => - (foreach ?res (set-diff ?req ?acq) + (foreach ?res ?req (printout warn "Locking resource " ?res crlf) (mutex-try-lock-async (resource-to-mutex ?res)) ) - *commit* 1e60e694dd420844574df2b89241c769fae7a456 - - - - - - - - - - Author: Till Hofmann <hofm...@kbsg.rwth-aachen.de> Date: Wed Jun 26 13:50:29 2019 +0200 Subject: clips-executive: keep track for which goal we requested a resource .../clips-executive/clips/resource-locks.clp | 69 +++++++++++++--------- 1 file changed, 42 insertions(+), 27 deletions(-) _Diff for modified files_: diff --git a/src/plugins/clips-executive/clips/resource-locks.clp b/src/plugins/clips-executive/clips/resource-locks.clp index 5732e41f3..351c7539c 100644 --- a/src/plugins/clips-executive/clips/resource-locks.clp +++ b/src/plugins/clips-executive/clips/resource-locks.clp @@ -37,6 +37,7 @@ "Request a mutex for each required resource if none of the respective mutexes is already locked or has a pending request." (goal (mode COMMITTED) + (id ?goal-id) (acquired-resources) (required-resources $?req&:(> (length$ ?req) 0))) (not (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) @@ -47,13 +48,14 @@ (foreach ?res ?req (printout warn "Locking resource " ?res crlf) (mutex-try-lock-async (resource-to-mutex ?res)) + (assert (resource-locks-resource-requested-for ?res ?goal-id)) ) ) -(defrule resource-locks-fast-reject-goal - "If a resource already locked, either by someone else or for a different - goal, we have not acquired any resources, and we have no pending requests, - then we can directly reject the goal." +(defrule resource-locks-fast-reject-goal-locked-by-other-agent + "If a resource already locked by someone else, we have not acquired any + resources, and we have no pending requests, then we can directly reject the + goal." (wm-fact (key cx identity) (value ?identity)) ?g <- (goal (mode COMMITTED) (id ?goal-id) @@ -62,49 +64,55 @@ ; The mutex is locked and there is no unprocessed request, which means that ; it was either locked by someone else or for a different goal. (mutex (name ?n&:(member$ (mutex-to-resource ?n) ?req)) - (state LOCKED) (request NONE) (locked-by ?locker)) + (state LOCKED) (request NONE) (locked-by ?locker&~?identity)) (not (mutex (name ?n1&:(member$ (mutex-to-resource ?n1) ?req)) (request ~NONE))) => - (if (neq ?locker ?identity) - (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) - " is already locked by " ?locker crlf) - else - (if (not (do-for-fact ((?og goal)) - (member$ (mutex-to-resource ?n) ?og:acquired-resources) - (printout warn "Rejecting goal " ?goal-id ", " - (mutex-to-resource ?n) - " is already locked for " ?og:id crlf))) - then - (printout error "Rejecting goal " ?goal-id ", resource " - (mutex-to-resource ?n) - " is already locked, but could not determine why!" crlf) - ) - ) + (printout warn "Rejecting goal " ?goal-id ", " (mutex-to-resource ?n) + " is already locked by " ?locker crlf) (modify ?g (mode FINISHED) (outcome REJECTED)) ) -(defrule resource-locks-lock-acquired - ?m <- (mutex (name ?res) (request LOCK) (response ACQUIRED)) +(defrule resource-locks-fast-reject-goal-locked-for-another-goal + "If a resource already locked for another goal, we have not acquired any + resources, and we have no pending requests, then we can directly reject the + goal." ?g <- (goal (mode COMMITTED) + (id ?goal) + (acquired-resources) + (required-resources $? ?res $?)) + (resource-locks-resource-requested-for ?res ?other-goal&~?goal) + (not (mutex (name ?n1&:(eq ?n1 (resource-to-mutex ?res))) + (request ~NONE))) + => + (printout warn "Rejecting goal " ?goal ", " ?res + " is already locked for " ?other-goal crlf) + (modify ?g (mode FINISHED) (outcome REJECTED)) +) + +(defrule resource-locks-lock-acquired + (resource-locks-resource-requested-for ?res ?goal-id) + ?m <- (mutex (name ?n&:(eq ?n (resource-to-mutex ?res))) + (request LOCK) (response ACQUIRED)) + ?g <- (goal (mode COMMITTED) (id ?goal-id) (required-resources $?req) (acquired-resources $?acq - &:(member$ (mutex-to-resource ?res) (set-diff ?req ?acq)))) + &:(member$ ?res (set-diff ?req ?acq)))) => - (modify ?g (acquired-resources (append$ ?acq (mutex-to-resource ?res)))) + (modify ?g (acquired-resources (append$ ?acq (mutex-to-resource ?n)))) (modify ?m (request NONE) (response NONE)) ) (defrule resource-locks-lock-rejected-release-acquired-resources "A lock was rejected, therefore release all acquired resources." - ?m <- (mutex (name ?res) + ?m <- (mutex (name ?n) (request LOCK) (response REJECTED|ERROR) (error-msg ?err)) - ?g <- (goal (mode COMMITTED) + ?g <- (goal (mode COMMITTED) (id ?goal-id) (required-resources $?req) (acquired-resources $?acq - &:(member$ (mutex-to-resource ?res) (set-diff ?req ?acq)))) + &:(member$ (mutex-to-resource ?n) (set-diff ?req ?acq)))) ; We cannot abort a pending request. Thus, we first need to wait to get ; responses for all requested locks. (not (mutex (name ?on&:(member$ (mutex-to-resource ?on) ?req)) @@ -166,3 +174,10 @@ (delete-member$ ?acq (mutex-to-resource ?res)))) (modify ?m (request NONE) (response NONE)) ) + +(defrule resource-locks-cleanup-lock-requests + ?request <- (resource-locks-resource-requested-for ?res ?goal-id) + (not (goal (id ?goal-id) (mode COMMITTED))) + => + (retract ?request) +) _______________________________________________ fawkes-commits mailing list fawkes-commits@lists.kbsg.rwth-aachen.de https://lists.kbsg.rwth-aachen.de/listinfo/fawkes-commits