Skip to content

Commit

Permalink
Run make format
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejboczar committed Jan 26, 2021
1 parent f1fba1c commit ec67d5d
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 572 deletions.
241 changes: 119 additions & 122 deletions rowhammer_tester/payload/ddr3lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,132 +8,129 @@
Instr = payload_ddr3_pb2.Instr
Payload = payload_ddr3_pb2.Payload


def VerifyInstr(ip: int, instr: Instr) -> bool:
if instr.HasField('mem'):
mem = instr.mem
if mem.opcode not in {Opcode.RD, Opcode.ACT, Opcode.PRE, Opcode.REF}:
return False
if not (0 < mem.timeslice < (1 << Instr.MemInstr.Bits.TIMESLICE)):
return False
if mem.rank != 0: # TODO: Add multi-rank support.
return False
if mem.bank >= 1 << Instr.MemInstr.Bits.BANK:
return False
if mem.addr >= 1 << Instr.MemInstr.Bits.ADDR:
return False
if mem.opcode == Opcode.RD and mem.addr % 8 != 0:
# We only ever want sequential (non-permuted) bursts.
return False
return True
if instr.HasField('nop'):
nop = instr.nop
if nop.opcode != Opcode.NOP:
return False
if not (0 < nop.timeslice < (1 << Instr.NopInstr.Bits.TIMESLICE)):
return False
return True
if instr.HasField('jmp'):
jmp = instr.jmp
if jmp.opcode != Opcode.JMP:
return False
if not (0 < jmp.offset < (1 << Instr.JmpInstr.Bits.OFFSET)):
return False
if ip < jmp.offset:
return False
if not (0 < jmp.count < (1 << Instr.JmpInstr.Bits.COUNT)):
return False
return True
return False
if instr.HasField('mem'):
mem = instr.mem
if mem.opcode not in {Opcode.RD, Opcode.ACT, Opcode.PRE, Opcode.REF}:
return False
if not (0 < mem.timeslice < (1 << Instr.MemInstr.Bits.TIMESLICE)):
return False
if mem.rank != 0: # TODO: Add multi-rank support.
return False
if mem.bank >= 1 << Instr.MemInstr.Bits.BANK:
return False
if mem.addr >= 1 << Instr.MemInstr.Bits.ADDR:
return False
if mem.opcode == Opcode.RD and mem.addr % 8 != 0:
# We only ever want sequential (non-permuted) bursts.
return False
return True
if instr.HasField('nop'):
nop = instr.nop
if nop.opcode != Opcode.NOP:
return False
if not (0 < nop.timeslice < (1 << Instr.NopInstr.Bits.TIMESLICE)):
return False
return True
if instr.HasField('jmp'):
jmp = instr.jmp
if jmp.opcode != Opcode.JMP:
return False
if not (0 < jmp.offset < (1 << Instr.JmpInstr.Bits.OFFSET)):
return False
if ip < jmp.offset:
return False
if not (0 < jmp.count < (1 << Instr.JmpInstr.Bits.COUNT)):
return False
return True
return False


class Rank:
def __init__(self, timing: Timing):
self.parameters = {
Opcode.RD: {
Opcode.RD: timing.ccd,
},
Opcode.ACT: {
Opcode.ACT: timing.rrd,
Opcode.REF: math.inf,
},
Opcode.PRE: {
Opcode.REF: timing.rp,
},
Opcode.REF: {
Opcode.ACT: timing.rfc,
Opcode.PRE: timing.rfc,
Opcode.REF: timing.rfc,
},
}
self.next_tick = {Opcode.RD: 0, Opcode.ACT: 0, Opcode.PRE: 0, Opcode.REF: 0}

# Special-case handling for tFAW.
self.prev_acts = collections.deque(maxlen = 4)
self.faw = timing.faw

# Banks.
self.banks = [
Bank(timing) for _ in range(1 << Instr.MemInstr.Bits.BANK)
]

def Execute(self, tick: int, instr: Instr.MemInstr) -> bool:
if tick < self.next_tick.get(instr.opcode, 0):
print('Rank timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick, self.next_tick[instr.opcode]))
return False

# Special-case handling for tFAW.
if instr.opcode == Opcode.ACT:
if len(self.prev_acts) == self.prev_acts.maxlen:
if tick - self.prev_acts[0] < self.faw:
print('tFAW timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick - self.prev_acts[0],
self.faw))
return False
self.prev_acts.append(tick)

if not self.banks[instr.bank].Execute(tick, instr):
return False

for opcode, parameter in self.parameters.get(instr.opcode, {}).items():
if self.next_tick[opcode] == math.inf:
self.next_tick[opcode] = tick + parameter
elif self.next_tick[opcode] < tick + parameter:
self.next_tick[opcode] = tick + parameter
return True
def __init__(self, timing: Timing):
self.parameters = {
Opcode.RD: {
Opcode.RD: timing.ccd,
},
Opcode.ACT: {
Opcode.ACT: timing.rrd,
Opcode.REF: math.inf,
},
Opcode.PRE: {
Opcode.REF: timing.rp,
},
Opcode.REF: {
Opcode.ACT: timing.rfc,
Opcode.PRE: timing.rfc,
Opcode.REF: timing.rfc,
},
}
self.next_tick = {Opcode.RD: 0, Opcode.ACT: 0, Opcode.PRE: 0, Opcode.REF: 0}

# Special-case handling for tFAW.
self.prev_acts = collections.deque(maxlen=4)
self.faw = timing.faw

# Banks.
self.banks = [Bank(timing) for _ in range(1 << Instr.MemInstr.Bits.BANK)]

def Execute(self, tick: int, instr: Instr.MemInstr) -> bool:
if tick < self.next_tick.get(instr.opcode, 0):
print(
'Rank timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick, self.next_tick[instr.opcode]))
return False

# Special-case handling for tFAW.
if instr.opcode == Opcode.ACT:
if len(self.prev_acts) == self.prev_acts.maxlen:
if tick - self.prev_acts[0] < self.faw:
print(
'tFAW timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick - self.prev_acts[0], self.faw))
return False
self.prev_acts.append(tick)

if not self.banks[instr.bank].Execute(tick, instr):
return False

for opcode, parameter in self.parameters.get(instr.opcode, {}).items():
if self.next_tick[opcode] == math.inf:
self.next_tick[opcode] = tick + parameter
elif self.next_tick[opcode] < tick + parameter:
self.next_tick[opcode] = tick + parameter
return True


class Bank:
def __init__(self, timing: Timing):
self.parameters = {
Opcode.RD: {
Opcode.PRE: timing.rtp,
},
Opcode.ACT: {
Opcode.RD: timing.rcd,
Opcode.ACT: math.inf,
Opcode.PRE: timing.ras,
},
Opcode.PRE: {
Opcode.RD: math.inf,
Opcode.ACT: timing.rp
def __init__(self, timing: Timing):
self.parameters = {
Opcode.RD: {
Opcode.PRE: timing.rtp,
},
Opcode.ACT: {
Opcode.RD: timing.rcd,
Opcode.ACT: math.inf,
Opcode.PRE: timing.ras,
},
Opcode.PRE: {
Opcode.RD: math.inf,
Opcode.ACT: timing.rp
}
}
}
self.next_tick = {
Opcode.RD: math.inf,
Opcode.ACT: 0,
Opcode.PRE: 0,
Opcode.REF: 0
}

def Execute(self, tick: int, instr: Instr.MemInstr) -> bool:
if tick < self.next_tick.get(instr.opcode, 0):
print('Bank timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick, self.next_tick[instr.opcode]))
return False

for opcode, parameter in self.parameters.get(instr.opcode, {}).items():
if self.next_tick[opcode] == math.inf:
self.next_tick[opcode] = tick + parameter
elif self.next_tick[opcode] < tick + parameter:
self.next_tick[opcode] = tick + parameter
return True
self.next_tick = {Opcode.RD: math.inf, Opcode.ACT: 0, Opcode.PRE: 0, Opcode.REF: 0}

def Execute(self, tick: int, instr: Instr.MemInstr) -> bool:
if tick < self.next_tick.get(instr.opcode, 0):
print(
'Bank timing violation for {}: {} < {}'.format(
Opcode.Name(instr.opcode), tick, self.next_tick[instr.opcode]))
return False

for opcode, parameter in self.parameters.get(instr.opcode, {}).items():
if self.next_tick[opcode] == math.inf:
self.next_tick[opcode] = tick + parameter
elif self.next_tick[opcode] < tick + parameter:
self.next_tick[opcode] = tick + parameter
return True
Loading

0 comments on commit ec67d5d

Please sign in to comment.