Esempio n. 1
0
def print_sens_brut(ret):
  sensitivity = ret.sensitivity
  brutality = ret.brutality

  prints("\nBMARK       sensitivity    brutality")
  for bmark,degr in sorted(sensitivity.items(), key=lambda x: x[1], reverse=True):
    brut = brutality[bmark]
    prints("{bmark:<11} {degr:>8.2f} {brut:>10.2f}")
Esempio n. 2
0
def print_sens_brut(ret):
    sensitivity = ret.sensitivity
    brutality = ret.brutality

    prints("\nBMARK       sensitivity    brutality")
    for bmark, degr in sorted(sensitivity.items(),
                              key=lambda x: x[1],
                              reverse=True):
        brut = brutality[bmark]
        prints("{bmark:<11} {degr:>8.2f} {brut:>10.2f}")
Esempio n. 3
0
def dead_opt_new(nr_vms:int=4, nr_samples:int=10, repeat:int=10, vms=None):
  """ Like old one but reports more data. """
  sys_speedup = []
  reloc_speedup  = []
  all_speedup = []
  for x in range(repeat):
    prints("ITERATION {x} out of {repeat}")
    wait_idleness(IDLENESS*4)
    sys, vm, all = dead_opt1(nr_vms=nr_vms, nr_samples=nr_samples, vms=vms)
    sys_speedup.append(sys)
    reloc_speedup += vm
    all_speedup += all
  return Struct(sys_speedup=sys_speedup, reloc_speedup=reloc_speedup, all_speedup=all_speedup)
Esempio n. 4
0
def brutforce(bmarks, ht_pairs=None):
  ht_pairs = topology.ht_pairs
  min_oh, max_oh = 10000, 0
  min_alloc =  max_alloc = None

  for cpu_alloc in permutations(topology.all):
    cpu_alloc = list(flatten(cpu_alloc))
    alloc = list(zip(bmarks, cpu_alloc))
    r = estimate(alloc, topology.ht_map, *params)
    if r < min_oh:
      min_oh = r
      min_alloc = alloc
    if r > max_oh:
      max_oh = r
      max_alloc = alloc
  prints("{min_oh:.2f} {min_alloc}\n{max_oh:.2f} {max_alloc}\n{topology.ht_map}")
  return min_alloc
Esempio n. 5
0
def real_loosers3(num:int=10, interval:int=10*1000, pause:float=0.1, vms=None):
  """ Detect starving applications. Improved version """
  shared_perf = defaultdict(list)
  frozen_perf = defaultdict(list)
  prints("real_loosers3 iterations ", end="")
  for i,x in enumerate(range(num)):
    prints("{i}/{num}", end=" "); sys.stdout.flush()
    shared_thr_sampling(num=1, interval=interval, result=shared_perf, vms=vms)
    freezing_sampling(num=1,   interval=interval, pause=0.1, result=frozen_perf, vms=vms)
    sleep(pause)

  result = {}
  for vm, sh_perf, fr_perf in dictzip(shared_perf, frozen_perf):
    ratio = mean(sh_perf) / mean(fr_perf)
    result[vm] = ratio
  result = sorted(result.items(), key=lambda v: v[1])
  print("Loosers: straight forward technique:\n", result)

  return result, shared_perf, frozen_perf
Esempio n. 6
0
def reverse(R2, Vmin, Vmax, Vdacmin, Vdacmax, Vref=1.21):
  """
    Id = (Vref - Vd) / Rd
    I2*R2 = V - Vref
    Vref = I1*R1 =>
      I1 = Vref / R1
    I2 + Id = I1 => 
      (V - Vref) / R2 + (Vref - Vd) / Rd = Vref / R1
      ----------------------------------------------
  """
  """
  (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd = Vref / R1     => R1 = (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd * Vref
  (Vmax - Vref) / R2 + (Vref - Vdacmin) / Rd = Vref / R1

  =>
  (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd = (Vmax - Vref) / R2 + (Vref - Vdacmin) / Rd
  
  (Vmin - Vref)*Rd + (Vref - Vdacmax)*R2 = (Vmax - Vref)*Rd +  (Vref - Vdacmin)*R2
  => 
  (Vmin - Vref)*Rd - (Vmax - Vref)*Rd = (Vref - Vdacmin)*R2 - (Vref - Vdacmax)*R2
  => (Vmin - Vref - Vmax + Vref)*Rd = (Vref - Vdacmin - Vref + Vdacmax) * R2
  (Vmin - Vmax) Rd = (Vdacmax-Vdacmin)* R2 =>
  Rd = (Vdacmax-Vdacmin)* R2 / (Vmin - Vmax)  #!
  -----------------------------------------------

  (V - Vref) / R2 + (Vref - Vd) / Rd = Vref / R1 =>
  R1 / Vref = (R2 * Rd) / ((V - Vref)*Rd + (Vref - Vd) * R2) =>
  R1 / Vref = R2 * Rd / ((V - Vref)*Rd + (Vref - Vd) * R2) =>
  R1  = R2 * Rd * Vref / ((V - Vref)*Rd + (Vref - Vd) * R2)
  """
  Rd  =  (Vdacmax-Vdacmin)* R2 / (Vmax-Vmin)
  R1  =  Vref / (Vmax/R2 - Vref*(R2 + Rd)/(R2*Rd) + Vdacmin/Rd)


  Idacmin = (Vdacmax - Vref) / Rd * 1000
  Idacmax = (Vdacmin - Vref) / Rd * 1000
  prints("Idacmin = {Idacmin:0.2f}mA, Idacmax={Idacmax:0.2f}mA")

  return R2, R1, Rd
Esempio n. 7
0
def reverse(R2, Vmin, Vmax, Vdacmin, Vdacmax, Vref=1.21):
    """
    Id = (Vref - Vd) / Rd
    I2*R2 = V - Vref
    Vref = I1*R1 =>
      I1 = Vref / R1
    I2 + Id = I1 => 
      (V - Vref) / R2 + (Vref - Vd) / Rd = Vref / R1
      ----------------------------------------------
  """
    """
  (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd = Vref / R1     => R1 = (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd * Vref
  (Vmax - Vref) / R2 + (Vref - Vdacmin) / Rd = Vref / R1

  =>
  (Vmin - Vref) / R2 + (Vref - Vdacmax) / Rd = (Vmax - Vref) / R2 + (Vref - Vdacmin) / Rd
  
  (Vmin - Vref)*Rd + (Vref - Vdacmax)*R2 = (Vmax - Vref)*Rd +  (Vref - Vdacmin)*R2
  => 
  (Vmin - Vref)*Rd - (Vmax - Vref)*Rd = (Vref - Vdacmin)*R2 - (Vref - Vdacmax)*R2
  => (Vmin - Vref - Vmax + Vref)*Rd = (Vref - Vdacmin - Vref + Vdacmax) * R2
  (Vmin - Vmax) Rd = (Vdacmax-Vdacmin)* R2 =>
  Rd = (Vdacmax-Vdacmin)* R2 / (Vmin - Vmax)  #!
  -----------------------------------------------

  (V - Vref) / R2 + (Vref - Vd) / Rd = Vref / R1 =>
  R1 / Vref = (R2 * Rd) / ((V - Vref)*Rd + (Vref - Vd) * R2) =>
  R1 / Vref = R2 * Rd / ((V - Vref)*Rd + (Vref - Vd) * R2) =>
  R1  = R2 * Rd * Vref / ((V - Vref)*Rd + (Vref - Vd) * R2)
  """
    Rd = (Vdacmax - Vdacmin) * R2 / (Vmax - Vmin)
    R1 = Vref / (Vmax / R2 - Vref * (R2 + Rd) / (R2 * Rd) + Vdacmin / Rd)

    Idacmin = (Vdacmax - Vref) / Rd * 1000
    Idacmax = (Vdacmin - Vref) / Rd * 1000
    prints("Idacmin = {Idacmin:0.2f}mA, Idacmax={Idacmax:0.2f}mA")

    return R2, R1, Rd
Esempio n. 8
0
def prettybt(exctype, exc_val, tb):
  frames = inspect.getinnerframes(tb)
  for frame, file, line, funcname, *other in frames:
    arginfo = inspect.getargvalues(frame)
    args = ", ".join(arginfo.args)
    f_locals = frame.f_locals
    if 'self' in f_locals:
      klass = f_locals['self'].__class__.__name__
      prints("${file}:${line}: ${klass}.${funcname}(${args}):")
    else:
      prints("${file}:${line}: ${funcname}(${args}):")
    tb = tb.tb_next
  prints("${exctype.__name__}: ${exc_val}")
Esempio n. 9
0
  R1  = R2 * Rd * Vref / ((V - Vref)*Rd + (Vref - Vd) * R2)
  """
  Rd  =  (Vdacmax-Vdacmin)* R2 / (Vmax-Vmin)
  R1  =  Vref / (Vmax/R2 - Vref*(R2 + Rd)/(R2*Rd) + Vdacmin/Rd)


  Idacmin = (Vdacmax - Vref) / Rd * 1000
  Idacmax = (Vdacmin - Vref) / Rd * 1000
  prints("Idacmin = {Idacmin:0.2f}mA, Idacmax={Idacmax:0.2f}mA")

  return R2, R1, Rd



if __name__ == '__main__':
  Rup   = 10000
  Vdacmin = 0.05
  Vdacmax = 3.3
  Vmin = 0.00
  Vmax = 15
  Rup, Rdown, Rdac = reverse(Rup, Vmin=Vmin, Vmax=Vmax, Vdacmin=Vdacmin, Vdacmax=Vdacmax)
  prints("Calculated resistors:\n Rup={Rup}, Rdown = {Rdown}, Rdac = {Rdac}")

  VminCalc = calc(Rup, Rdown, Rdac, Vdacmax)
  VmaxCalc = calc(Rup, Rdown, Rdac, Vdacmin)
  prints("Vmin={Vmin:.2f} (checked {VminCalc:.2f})\nVmax={Vmax:.2f} (checked: {VmaxCalc:.2f})")
  ratio = (Rup + Rdown) / Rdown;
  prints("ratio: {ratio:.2f}")
  #print(calc(5100, 530, 300, 3))

Esempio n. 10
0
def analyze(isolated, joint, stats=None):
  bmarks = sorted(isolated.keys())
  events = sorted(stats['blosc'])        # all events
  sensitivity = OrderedDefaultDict(int)
  brutality = OrderedDefaultDict(int)
  ret = DefaultStruct()

  # print header
  print()
  print("          ", end='')
  [prints("{bmark:>10}", end='') for bmark in bmarks]
  print()
  # print table
  for fg in bmarks:
    prints("{fg:<10}", end='')
    for bg in bmarks:
      if (fg, bg) in joint:
        fg_perf, bg_perf = joint[fg, bg]
      else:
        bg_perf, fg_perf = joint[bg, fg]
      fg_degr = 1 - fg_perf / isolated[fg]
      bg_degr = 1 - bg_perf / isolated[bg]
      sensitivity[fg] += fg_degr
      sensitivity[bg] += bg_degr
      brutality[fg]   += bg_degr
      brutality[bg]   += fg_degr
      prints("{fg_degr:>10.1%}", end='')
    print()

  # normalize
  for k,v in sensitivity.items():
    sensitivity[k] = v / len(bmarks)
  for k,v in brutality.items():
    brutality[k] = v / len(bmarks)

  for themap, result in [(sensitivity, ret.sensitivity),
                         (brutality, ret.brutality)]:
    result.correlation = []
    result.regression  = {}

    for event in events:
      X, Y = [], []
      for bmark in bmarks:
        coeff = themap[bmark]
        count = stats[bmark][event]
        X.append(count)
        Y.append(coeff)
        # prints("{bmark:<10}: sens:{sens:<6.2f} brut:{brut:.2f}")
      corr, p = pearsonr(X, Y)
      if abs(p) > 0.05:
        continue
      result.correlation.append((event, corr, p))
      prints("correlation {event:<21} {corr:+.3f} {p:.3f}")
      result.regression[event] = np.polyfit(X, Y, 1)
    result.correlation.sort(key=lambda v: -abs(v[1]))
  return ret

  for (bmark1, bmark2), (ipc1_sh, ipc2_sh) in joint.items():
    ipc1_iso = isolated[bmark1]
    ipc2_iso = isolated[bmark2]
    ratio1   = ipc1_sh / ipc1_iso
    ratio2   = ipc2_sh / ipc2_iso
    prints("{bmark1:<10} {bmark2:<10}: {degr1:>.2f} {degr2:>8.2f}")
Esempio n. 11
0
def print_correlation(ret):
  for event, (corr, p) in ret.correlation:
    if p > 0.05:
      continue
    prints("{event:<25} {corr:>8.4f} {p:>8.4f}")
Esempio n. 12
0
def dead_opt1(nr_vms:int=4, nr_samples:int=10, interval=200, vms=None):
  """ Like dead_opt_n but more output stats so we can add more plots to the article"""
  [vm.start() for vm in vms]
  cpus_ranked = cpu_enum()

  #report("before start")
  # SPAWN
  active_vms = []
  active_cpus = []
  #benchmarks = "matrix sdagp matrix sdagp".split()
  benchmarks = list(basis.keys())
  for i, vm, cpu in zip(range(nr_vms), vms, cpus_ranked):
    #bmark, cmd = choice(benchmarks)
    bmark = benchmarks.pop(0)
    cmd = basis[bmark]
    print(cpu, bmark, vm)
    vm.pipe = vm.Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
    vm.bname = bmark
    vm.set_cpus([cpu])
    active_cpus.append(cpu)
    active_vms.append(vm)
    sleep(0.2)  # do not start them all simultaneusly

  print("warm-up, active vms:", active_vms)
  sleep(10)
  print("TODO: shorter sleep")

  stats, perf_before, _ = real_loosers3(interval=interval, num=nr_samples, vms=active_vms)
  p1, ipc1 = report("after finding loosers")
  print(stats)
  relocated_vms = []
  for i, (vm, degr) in zip(range(2), stats):
    print(vm, vm.bname)
    relocated_vms.append(vm)
    for cpu in topology.no_ht:
      if cpu not in active_cpus:
        #TODO: remove old cpu
        vm.set_cpus([cpu])
        active_cpus.append(cpu)

  stats_after, perf_after, _ = real_loosers3(interval=interval, num=nr_samples, vms=active_vms)
  prints("BEFORE: {perf_before}\n AFTER: {perf_after}")
  p2, ipc2 = report("after fixing loosers")

  for vm in vms:
    if hasattr(vm, "pipe") and vm.pipe:
      vm.pipe.killall()
      vm.pipe = None

  # RESULT
  sys_speedup = p2 / p1
  reloc_speedup  = []
  all_speedup = []
  #for vm in perf_after.keys():
  for vm in relocated_vms:
    r = mean(perf_after[vm]) / mean(perf_before[vm])
    reloc_speedup.append(r)
  for vm in active_vms:
    r = mean(perf_after[vm]) / mean(perf_before[vm])
    all_speedup.append(r)
  print("SPEEDUP:", sys_speedup)
  print("IMPROVEMENTS:", all_speedup)
  return sys_speedup, reloc_speedup, all_speedup
Esempio n. 13
0
def analyze(isolated, joint, stats=None):
    bmarks = sorted(isolated.keys())
    events = sorted(stats['blosc'])  # all events
    sensitivity = OrderedDefaultDict(int)
    brutality = OrderedDefaultDict(int)
    ret = DefaultStruct()

    # print header
    print()
    print("          ", end='')
    [prints("{bmark:>10}", end='') for bmark in bmarks]
    print()
    # print table
    for fg in bmarks:
        prints("{fg:<10}", end='')
        for bg in bmarks:
            if (fg, bg) in joint:
                fg_perf, bg_perf = joint[fg, bg]
            else:
                bg_perf, fg_perf = joint[bg, fg]
            fg_degr = 1 - fg_perf / isolated[fg]
            bg_degr = 1 - bg_perf / isolated[bg]
            sensitivity[fg] += fg_degr
            sensitivity[bg] += bg_degr
            brutality[fg] += bg_degr
            brutality[bg] += fg_degr
            prints("{fg_degr:>10.1%}", end='')
        print()

    # normalize
    for k, v in sensitivity.items():
        sensitivity[k] = v / len(bmarks)
    for k, v in brutality.items():
        brutality[k] = v / len(bmarks)

    for themap, result in [(sensitivity, ret.sensitivity),
                           (brutality, ret.brutality)]:
        result.correlation = []
        result.regression = {}

        for event in events:
            X, Y = [], []
            for bmark in bmarks:
                coeff = themap[bmark]
                count = stats[bmark][event]
                X.append(count)
                Y.append(coeff)
                # prints("{bmark:<10}: sens:{sens:<6.2f} brut:{brut:.2f}")
            corr, p = pearsonr(X, Y)
            if abs(p) > 0.05:
                continue
            result.correlation.append((event, corr, p))
            prints("correlation {event:<21} {corr:+.3f} {p:.3f}")
            result.regression[event] = np.polyfit(X, Y, 1)
        result.correlation.sort(key=lambda v: -abs(v[1]))
    return ret

    for (bmark1, bmark2), (ipc1_sh, ipc2_sh) in joint.items():
        ipc1_iso = isolated[bmark1]
        ipc2_iso = isolated[bmark2]
        ratio1 = ipc1_sh / ipc1_iso
        ratio2 = ipc2_sh / ipc2_iso
        prints("{bmark1:<10} {bmark2:<10}: {degr1:>.2f} {degr2:>8.2f}")
Esempio n. 14
0
def print_correlation(ret):
    for event, (corr, p) in ret.correlation:
        if p > 0.05:
            continue
        prints("{event:<25} {corr:>8.4f} {p:>8.4f}")
Esempio n. 15
0
    R1 = Vref / (Vmax / R2 - Vref * (R2 + Rd) / (R2 * Rd) + Vdacmin / Rd)

    Idacmin = (Vdacmax - Vref) / Rd * 1000
    Idacmax = (Vdacmin - Vref) / Rd * 1000
    prints("Idacmin = {Idacmin:0.2f}mA, Idacmax={Idacmax:0.2f}mA")

    return R2, R1, Rd


if __name__ == '__main__':
    Rup = 10000
    Vdacmin = 0.05
    Vdacmax = 3.3
    Vmin = 0.00
    Vmax = 15
    Rup, Rdown, Rdac = reverse(Rup,
                               Vmin=Vmin,
                               Vmax=Vmax,
                               Vdacmin=Vdacmin,
                               Vdacmax=Vdacmax)
    prints("Calculated resistors:\n Rup={Rup}, Rdown = {Rdown}, Rdac = {Rdac}")

    VminCalc = calc(Rup, Rdown, Rdac, Vdacmax)
    VmaxCalc = calc(Rup, Rdown, Rdac, Vdacmin)
    prints(
        "Vmin={Vmin:.2f} (checked {VminCalc:.2f})\nVmax={Vmax:.2f} (checked: {VmaxCalc:.2f})"
    )
    ratio = (Rup + Rdown) / Rdown
    prints("ratio: {ratio:.2f}")
    #print(calc(5100, 530, 300, 3))