Skip to content

Instantly share code, notes, and snippets.

Nan Xiao NanXiao

Block or report user

Report or block NanXiao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@NanXiao
NanXiao / parse_mem_info.cpp
Created Jun 4, 2019
Parse /proc/meminfo file
View parse_mem_info.cpp
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
int main()
{
const std::string meminfo_file("/proc/meminfo");
std::ifstream ifs(meminfo_file);
@NanXiao
NanXiao / nmi-interrupts.txt
Created May 27, 2019 — forked from wmealing/nmi-interrupts.txt
NMI interrupts and the joy they bring.
View nmi-interrupts.txt
A non-maskable interrupt (NMI) is an interrupt type which differs from standard interrupt mechanism by enforcing attention from the interrupt processor (usually the CPU). This solution discusses an NMI is in more depth and how they are handled.
### What is an Interrupt ? ###
Modern systems architecture has created tightly coupled connect between system components. Work for components can be handed off to a component for completion. Rather than wait for the component the main CPU can be tasked to do other pending work.
When the component has completed its work it will raise a signal to the main processor. The main processor considers this signal an "interrupt", as the current work on the CPU will be interrupted immediately Each component has a number assigned to it.
### Why "mask" an interrupt ? ###
View parallel.c
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#define CPU_NUM (104)
#define LOOP_NUM (100)
#define ARRAY_SIZE (CPU_NUM * LOOP_NUM)
double a[ARRAY_SIZE], b[ARRAY_SIZE], c[ARRAY_SIZE];
View nccl_ex.cu
/* compile:
* /opt/cuda/bin/nvcc -ccbin g++ -gencode=arch=compute_60,code=sm_60 -std=c++11 -O3 -I/usr/local/nccl/include/ -L/opt/cuda/lib64 -lcudart -lrt -L/usr/local/nccl/lib -lcurand -lnccl -lnvToolsExt -o nccl_ex nccl_ex.cu
*/
#include "nccl.h"
#include <stdio.h>
#define GPU_COUNT (4)
#define CUDACHECK(cmd) do { \
@NanXiao
NanXiao / bfd_test.c
Created Oct 17, 2017
A simple bfd usage example
View bfd_test.c
#define PACKAGE "bfd_test"
#include <iostream>
#include <bfd.h>
int main(int argc, char** argv)
{
if (argc == 1)
{
std::cout << "Lack input file!\n";
return 1;
View calculate.go
package main
import (
"fmt"
"net/http"
"encoding/json"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.clever.com/v1.1/sections", nil)
View server.go
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"encoding/json"
"strconv"
"sync"
)
View freebsd_hello_driver.c
#include <sys/types.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/errno.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/uio.h>
static d_open_t hello_open;
View "rpm --help" output
Usage: rpm [OPTION...]
Query/Verify package selection options:
-a, --all query/verify all packages
-f, --file query/verify package(s) owning file
-g, --group query/verify package(s) in group
-p, --package query/verify a package file
--pkgid query/verify package(s) with package identifier
--hdrid query/verify package(s) with header identifier
--triggeredby query the package(s) triggered by the package
You can’t perform that action at this time.