Skip to content

Instantly share code, notes, and snippets.

View jrziviani's full-sized avatar

Jose R. Ziviani jrziviani

View GitHub Profile
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <regex>
#include <tuple>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
@jrziviani
jrziviani / qemu-tracing.md
Created May 14, 2018 17:52 — forked from mcastelino/qemu-tracing.md
Tracing QEMU-KVM Interactions

Tracing QEMU-KVM Interactions

But default in linux you can figure out how many times and for what reasons there is a VM Exit from a VM into the kvm kernel module. However given the ubiquity of vhost and the ability of kvm to emulate most device models directly in the kernel, most of those VM exits do not result in a transition from host kernel into the QEMU. The transitions from VM -> kvm -> QEMU are typically the most expensive.

Here we try to figure out how many of the VM Exits result in the invocation of QEMU.

Tracking VM-KVM Interactions

This can be done very simply with perf

#include <sys/mman.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <altivec.h>
#include <stdlib.h>
#define DEVICE "/dev/mem"
#define ulong unsigned long
@jrziviani
jrziviani / visitors.cpp
Created October 30, 2017 10:45
expression client
class expression_t
{
public:
virtual int accept(expression_visitor &v) = 0;
virtual ~expression_t() {}
};
using expression = unique_ptr<expression_t>;
class type_number : public expression_t
{
int calculate_steps1(int stp)
{
if (stp == 0)
return 1;
if (stp == 1)
return 1;
if (stp == 2)
return 2;
return calculate_steps1(stp - 3) + calculate_steps1(stp - 2) + calculate_steps1(stp - 1);
long long make_change(vector<int> coins, int money) {
long int t[money + 1][coins.size() + 1];
for (size_t i = 0; i <= money; i++)
t[i][0] = 0;
for (size_t i = i; i <= coins.size(); i++)
t[0][i] = 1;
for (size_t i = 1; i <= money; i++) {
#include <vector>
int solution(vector<int> &A) {
vector<int> st(A.size() + 1);
st[0] = A[0];
int last_max = 0;
for (size_t i = 1; i < A.size(); i++) {
st[i] = max(st[i - 1], st[last_max]) + A[i];
st[last_max] = max(st[last_max], st[i - 1]);
#include <cstdint>
#include <iostream>
#include <memory>
#include <cassert>
using namespace std;
template<typename T>
class line
{
#include <iostream>
#include <memory>
#include <cstdint>
using namespace std;
struct x
{
int32_t xa;
unique_ptr<double[]> xb;
@jrziviani
jrziviani / latency_numbers.md
Created June 5, 2017 00:16 — forked from GLMeece/latency_numbers.md
Latency Numbers Every Programmer Should Know - MarkDown Fork

Latency Comparison Numbers

Note: "Forked" from Latency Numbers Every Programmer Should Know

Event Nanoseconds Microseconds Milliseconds Comparison
L1 cache reference 0.5 - - -
Branch mispredict 5.0 - - -
L2 cache reference 7.0 - - 14x L1 cache
Mutex lock/unlock 25.0 - - -