Library mcertikos.objects.cpulocaldef.HTicketLockOpGenDef


This file provide the contextual refinement proof between MALInit layer and MALOp layer
Require Import Coqlib.
Require Import Errors.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Op.
Require Import Smallstep.
Require Import Values.
Require Import Memory.
Require Import Maps.
Require Import Constant.
Require Import GlobIdent.
Require Import AbstractDataType.
Require Import GlobalOracle.

Require Import liblayers.compcertx.Stencil.
Require Import liblayers.compat.CompatLayers.
Require Import AuxStateDataType.
Require Import RealParams.
Require Import LogReplay.

Notation of the refinement relation

Section Refinement.

  Local Open Scope string_scope.
  Local Open Scope error_monad_scope.
  Local Open Scope Z_scope.

  Context `{real_params: RealParams}.

  Section WITHMEM.

    Context `{Hstencil: Stencil}.
    Context `{Hmem: Mem.MemoryModelX}.
    Context `{Hmwd: UseMemWithData mem}.

    Fixpoint relate_log (l: MultiLog): option(MultiLog × list nat) :=
      match l with
        | nilSome (nil, nil)
        | (TEVENT i e) ::
          match relate_log with
            | Some (ll, tq)
              match e with
                | TTICKET
                  match with
                    | INC_TICKET p
                      Some (ll, tq ++ (p::nil))
                    | GET_NOW
                      Some (ll, tq)
                    | HOLD_LOCK
                      match tq with
                        | p:: tq´
                          Some ((TEVENT i (TTICKET (WAIT_LOCK p))) :: ll, tq)
                        | _None
                      end
                    | INC_NOW
                      match tq with
                        | _:: tq´
                          Some ((TEVENT i (TTICKET REL_LOCK))::ll, tq´)
                        | _None
                      end
                    | _None
                  end
                | TSHARED _
                  Some ((TEVENT i e) :: ll, tq)
              end
            | _None
          end
      end.

    Inductive relate_ticket_log_type: MultiLogTypeMultiLogTypeProp :=
    | RELATE_TICKET_LOG_TYPE_UNDEF:
        relate_ticket_log_type MultiUndef MultiUndef
    | RELATE_TICKET_LOG_TYPE_DEF:
         l tq
               (Hrelate_ticket_log: relate_log l = Some (, tq)),
          relate_ticket_log_type (MultiDef ) (MultiDef l).

    Inductive relate_ticket_log_pool: MultiLogPoolMultiLogPoolProp :=
    | RELATE_TICKET_LOG_POOL:
         l
               (Hrelate_ticket_log_type:
                   index ofs z
                         (Hrange: index2Z index ofs = Some z),
                    relate_ticket_log_type (ZMap.get z l) (ZMap.get z )),
         relate_ticket_log_pool l .

    Context `{waittime: WaitTime}.

    Fixpoint CalSumWait (l: list nat) :=
      match l with
        | nilO
        | a :: ⇒ (4 + a + CalSumWait ) % nat
      end.

    Definition rm_head {A: Type} (l: list A) :=
      match l with
        | nilnil
        | _ ::
      end.

    Definition CalStatus (h: head_status) :=
      match h with
        | LEMPTYO
        | LHOLD ⇒ 1%nat
        | LGET ⇒ 2%nat
      end.

    Definition decrease_number (self_c other_c: nat) (h: head_status) (tq: list nat) :=
      match h with
        | LEMPTY ⇒ (other_c + (CalSumWait tq) × fairness) % nat
        | _ ⇒ (other_c + (self_c + CalSumWait (rm_head tq) + CalStatus h) × fairness)%nat
      end.

    Definition CalWaitTime (l: list nat) :=
      S (fairness + (CalSumWait l) × fairness).

    Inductive relate_ticket_oracle: MultiOracleMultiOracleProp :=
    | RELATE_ORACLE:
         o1 o2
               (Hrelate_ticket_oracle_res:
                   i l1 l2 tq bound
                         (Hrelate_log: relate_log l2 = Some (l1, tq)),
                    let l20 := (TEVENT i (TTICKET (INC_TICKET bound))) :: o2 i l2 ++ l2 in
                     self_c other_c b q tq0 l2´
                           (HCal: Q_CalLock l20 = Some (self_c, other_c, b, q, tq0))
                           (HWait: Q_CalWait (CalWaitTime tq0) i l20 o2 = Some l2´),
                     tq´, relate_log l2´ = Some (o1 i l1 ++ l1, tq´)),
          relate_ticket_oracle o1 o2.

    Inductive relate_ticket_oracle_pool: MultiOraclePoolMultiOraclePoolProp :=
    | RELATE_ORACLE_POOL:
         o1 o2
               (Hrelate_ticket_oracle:
                   index ofs z
                         (Hrange: index2Z index ofs = Some z),
                    relate_ticket_oracle (ZMap.get z o1) (ZMap.get z o2)),
          relate_ticket_oracle_pool o1 o2.

  End WITHMEM.

End Refinement.