Skip to content

Instantly share code, notes, and snippets.

View wuzw10's full-sized avatar

Zhenwei wuzw10

  • Changsha Hunan
View GitHub Profile
@wuzw10
wuzw10 / timer.c
Created March 30, 2017 03:02
get time at different granularities
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#define BILLION 1000000000L;
int main( int argc, char **argv )
{
struct timespec start, stop;
@wuzw10
wuzw10 / MPI_Allreduce
Created March 14, 2016 14:33
SDN-enhanced MPI
int SDN_MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
{
int rank, size, sock, ret;
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &size);
if (rank == 0) {
sock = connect_controller();
install_allreduce_rules(sock, size, 1);
@wuzw10
wuzw10 / DSA hw
Created October 8, 2015 14:35
DSA 2015
上浮操作实现
问题描述
读入一个字符串。按照数组下标顺序依次将字符串中的字符插入到堆结构中(初始堆结构为空)。每在堆结构中插入一个元素,按数组下标顺序输出堆结构中的元素。
直至建立一个包含输入字符串中所有字符元素的堆结构。
输入格式
字符串 (长度不超过1000个字符)
输出格式
依次按照数组下标顺序输出堆结构内容
样例输入
THANKYOU
@wuzw10
wuzw10 / networks
Created December 14, 2014 10:22
Architecture
interconnection networks -- packet switching networks
low-latency interconnection (as opposed to traditional packet switching networks)
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"myid"];
[self.navigationController pushViewController:controller animated:YES];
@wuzw10
wuzw10 / 中断相关寄存器
Last active August 29, 2015 14:01
中断屏蔽问题以及多栈问题
x86
From Wikipedia, the free encyclopedia
(Redirected from IF (x86 flag))
IF (Interrupt Flag) is a system flag bit in the x86 architecture's FLAGS register, which determines whether or not the CPU will handle maskable hardware interrupts.[1]
The bit, which is bit 9 of the FLAGS register, may be set or cleared by programs with sufficient privileges, as usually determined by the Operating System. If the flag is set to 1, maskable hardware interrupts will be handled. If cleared (set to 0), such interrupts will be ignored. IF does not affect the handling of non-maskable interrupts or software interrupts generated by the INT instruction.
x86 FLAGS寄存器的第9位是IF(Interrupt flag)
置1响应中断
置0忽略中断
IF不会影响non-maskable中断和软中断(INT)的响应
@wuzw10
wuzw10 / __do_exit
Last active August 29, 2015 14:01
proc_exit
// __do_exit - cause a thread exit (use do_exit, do_exit_thread instead)
// 1. call exit_mmap & put_pgdir & mm_destroy to free the almost all memory space of process
// 2. set process' state as PROC_ZOMBIE, then call wakeup_proc(parent) to ask parent reclaim itself.
// 3. call scheduler to switch to other process
static int __do_exit(void)
{
if (current == idleproc) {
panic("idleproc exit.\n");
}
if (current == initproc) {
execution of an SVC instruction at a priority equal or higher than SVCall
svc指令在一个大于等于svcall的优先级下执行
The original NuttX implementation used this PRIMASK register to enable and disable exceptions. Things now get interesting in the sequence of logic listed above because the PRIMASK bit also disables the SVCALL exception! So, instead of taking the SVCALL exception vector, the Cortex-M3/4 generates a hardfault exception (see ARM.com's discussion of Activation Levels. These hardfaults are not really a problem; the design of the NuttX hardfault handler expects these exceptions and does the right thing. However, the occurrence of hardfaults may come as a surprise to many people – and especially to some debuggers.
使用PRIMASK寄存器进行开关中断
PRIMASK位也会禁止SVCALL异常
所以在PRIMASK为1时,Cortex-M3会产生HardFault异常,而不是执行SVCALL异常处理。
@wuzw10
wuzw10 / do_mmap函数
Last active August 29, 2015 14:01
mmuless dommap简要分析
//mmuless的情形下,就是把制定的文件中的内容拷贝到内存中来。
unsigned long do_mmap(struct file * file, unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long off)
{
void * result;
struct mm_tblock_struct * tblock;
/* An ENOSYS error indicates that mmap isn't possible (as opposed to
tried but failed) so we'll fall through to the copy. */
@wuzw10
wuzw10 / ARCHIVE
Last active August 29, 2015 14:01
静态库
.a archive “存档”格式:
一组被连接起来的可重定位目标文件的集合
使用gnu ar工具进行创建和修改
静态库文件(.a):
在链接时,链接器将只拷贝被应用程序引用的目标模块
《深入理解计算机系统》例题学习:
gcc -c addvec.c multvec.c
ar res libvector.a addvec.o multvec.o
gcc -O2 -c main.c