Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sorted_ipc_queues invariant #836

Merged
merged 9 commits into from
Dec 20, 2024
Merged

Conversation

michaelmcinerney
Copy link
Contributor

@michaelmcinerney michaelmcinerney commented Dec 10, 2024

Please see the commit messages for what is here. It might be best to review the files in the order in which they would appear in jedit. So for example, AInvs before Refine, and earlier files in AInvs before later files in AInvs.

As usual, there are many lemmas that we may want to move up, or to have in master, and I would be happy to do that. I have moved many of the lemmas around, and I'll try to indicate them with comments. The diff is not very accurate, and some of what appears as green or red isn't anything I have actually touched.

I'll try some things out to hopefully reduce the number of times I remove comp_apply from the simp set.

I have weakened valid_ep' and valid_ntfn' by removing some of the properties that can be crossed from the abstract state analogues. This was done because proving distinctness was a bit of a pain with the ordered insert. So I have added some asserts in the Haskell for distinctness of these queues.

@michaelmcinerney michaelmcinerney force-pushed the michaelm-sorted_ipc_queues branch 2 times, most recently from 3e285fe to 9e82e28 Compare December 10, 2024 23:58
@michaelmcinerney michaelmcinerney self-assigned this Dec 11, 2024
@michaelmcinerney michaelmcinerney added the MCS related to `rt` branch and mixed-criticality systems label Dec 11, 2024
@michaelmcinerney michaelmcinerney marked this pull request as ready for review December 11, 2024 03:31
zprios' \<leftarrow> return $ filter (\<lambda>(_, p). p \<ge> prio) zprios
@ [(tptr, prio)]
@ filter (\<lambda>(_, p). p < prio) zprios;
return (map fst zprios')
od"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comprehension nitpick: if it's placing the tptr into a list such that it's sorted, does it still make sense to call it "append" without comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it'd be more like an insert. I suspect the name hasn't changed in C either, but we could still do better in the specs.

apply (rule hoare_lift_Pf[where f=ep_queues_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=prios_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=eps_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=ntfns_of, rotated], wpsimp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you had a lifting lemma for valid_sched_pred_strong, you could apply that here and then wp most of the conditions away; the hoare_lift_Pf way looks a bit uphill and happens 3 times in this file, so presumably also on RISCV64

Comment on lines 35 to 41
lemma set_pt_prios_of[wp]:
"set_pt ptr pt \<lbrace>\<lambda>s. P (prios_of s)\<rbrace>"
by (set_object_easy_cases def: set_pt_def)

lemma set_pd_prios_of[wp]:
"set_pd ptr pd \<lbrace>\<lambda>s. P (prios_of s)\<rbrace>"
by (set_object_easy_cases def: set_pd_def)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be proving P (tcbs_of s) here (and wherever we can), because that's the more general case that includes prios_of and all other tcb projections.

Comment on lines +92 to +94
for eps_of[wp]: "\<lambda>s. P (eps_of s)"
and ntfns_of[wp]: "\<lambda>s. P (ntfns_of s)"
and prios_of[wp]: "\<lambda>s. P (prios_of s)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these 3 always occur together: I wonder if there is a combinator that we could build so that we only have to prove one lemma and then apply a rule or something else that is automatic to get all three together. Not for this PR, but in general for projections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action necessary for this, but if someone has an idea, do let me know)

apply (rule hoare_lift_Pf[where f=ep_queues_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=prios_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=eps_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=ntfns_of, rotated], wpsimp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oo, another candidate for that lifting rule

apply (rule hoare_lift_Pf[where f=ep_queues_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=prios_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=eps_of, rotated], wpsimp)
apply (rule hoare_lift_Pf[where f=ntfns_of, rotated], wpsimp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, lifting rule

apply (rule hoare_lift_Pf2[where f=ntfn_queues_of, rotated], wpsimp)
apply (rule hoare_lift_Pf2[where f=prios_of, rotated], wpsimp)
apply (rule hoare_lift_Pf2[where f=eps_of, rotated], wpsimp)
apply (rule hoare_lift_Pf2[where f=ntfns_of, rotated], wpsimp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anothere one for team lift

@@ -26550,6 +27301,7 @@ lemma call_kernel_valid_sched:
\<and> cur_sc_offset_sufficient (consumed_time s) s\<rbrace>
call_kernel e
\<lbrace>\<lambda>_. valid_sched :: det_state \<Rightarrow> _\<rbrace>"
supply comp_apply[simp del]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to take this opportunity to express concern at the size of DetSchedSchedule_AI on rt. My browser took longer than my tea does to brew in order to open this file's diff for review.

@Xaphiosis
Copy link
Member

I like how you structured the proof of this invariant, and the way the asserts are lining up and not polluting Refine works out well. I didn't spot anything style-wise, and also appreciated where you pointed out a bunch of lemmas were moved.

I think the outstanding non-minor issues from my side are:

  • the over-use of hoare_lift_Pf rules indicates missing lifting rules; hoare_lift_Pf rules are generally avoided if possible because, amongst other issues, they nearly always apply and so can loop, and are the antithesis of automation
  • you are correct about the opt_map_Some_comp situation. Apparently, this might be able to be addressed with making ||> a definition, and we might want to give this a go before we merge this PR

@michaelmcinerney michaelmcinerney force-pushed the michaelm-sorted_ipc_queues branch from 9e82e28 to 5b6e657 Compare December 12, 2024 07:30
@michaelmcinerney
Copy link
Contributor Author

I think I have addressed most of what we would like to change for this PR, with the exception of renaming tcb_ep_append/tcbEPAppend to tcb_ep_insert/tcbEPInsert. There are also further lemmas that I could move to Lib. If we would very much like those tasks done as part of this PR, then I could do that, but I would prefer doing those in separate PRs, if that is OK.

@Xaphiosis
Copy link
Member

I think I have addressed most of what we would like to change for this PR, with the exception of renaming tcb_ep_append/tcbEPAppend to tcb_ep_insert/tcbEPInsert. There are also further lemmas that I could move to Lib. If we would very much like those tasks done as part of this PR, then I could do that, but I would prefer doing those in separate PRs, if that is OK.

Fine to do separately. Don't forget to make the issue for the misc/lifting/hoare_liftPf situation if you haven't already. Someone should double-check the squashed commits once they're squashed, but from my side this looks good.

@michaelmcinerney
Copy link
Contributor Author

Here's my issue for the heap projections: #841

Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! I have nothing further to add over the minor queries from before and Raf's thorough review.

@lsf37
Copy link
Member

lsf37 commented Dec 19, 2024

And nice job on resolving the comp_apply issue, that went even better than I expected.

Done in order to avoid unwanted interactions with comp_apply

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Done in order to avoid unwanted simplification of heaps which
are defined via multiple uses of opt_map_Some

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
This rule is no longer needed, now that opt_map_Some is not
defined in terms of comp

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
This adds the invariant sorted_ipc_queues, which states that the ipc
queues are sorted by the priority of the TCB. More specifically,
the queues are nonincreasing with respect to the priority of the TCB.

This additionally uses the filter operation in the specification
of tcb_ep_append and tcb_ep_dequeue.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
@michaelmcinerney michaelmcinerney force-pushed the michaelm-sorted_ipc_queues branch from 747ada7 to 6e00090 Compare December 20, 2024 05:18
@michaelmcinerney
Copy link
Contributor Author

I've force pushed to update this PR so that it now consists of the commits from #845 ("Some changes for Lib") cherry-picked onto the rt branch, plus squashed commits for the new work for sorted_ipc_queues

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
@michaelmcinerney michaelmcinerney force-pushed the michaelm-sorted_ipc_queues branch from 6e00090 to bff057f Compare December 20, 2024 06:31
@michaelmcinerney michaelmcinerney merged commit b91e1d9 into rt Dec 20, 2024
11 checks passed
@michaelmcinerney michaelmcinerney deleted the michaelm-sorted_ipc_queues branch December 20, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MCS related to `rt` branch and mixed-criticality systems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants