static void power_clk_work_func(struct work_struct *dummy) { #ifndef CONFIG_COMMON_CLK read_source(&power_ctx.gpu); read_source(&power_ctx.emc); check_clks(); #endif }
static int cpu_notifier_call(struct notifier_block *nb, unsigned long val, void *ptr) { read_source(&power_ctx.cpu); #ifndef CONFIG_COMMON_CLK read_source(&power_ctx.gpu); read_source(&power_ctx.emc); #endif check_clks(); return 0; }
Document createDocument(std::istream& stream, const ParseParameters& params, const std::string& id) { Platform xmlplat; std::string data; // Try to intelligently size the read buffer based upon the // stream length. std::streampos pos = stream.tellg(); stream.seekg(0, std::ios::end); std::streampos len = stream.tellg() - pos; if (len > 0) data.reserve(static_cast<std::string::size_type>(len)); stream.seekg(pos); data.assign(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>()); xercesc::MemBufInputSource source(reinterpret_cast<const XMLByte *>(data.c_str()), static_cast<XMLSize_t>(data.size()), String(id)); xercesc::XercesDOMParser parser; setup_parser(parser, params); read_source(parser, source); return Document(parser.adoptDocument(), true); }
int main(int argc, char** argv) { int i; for(i = 0; i < NAL; i++) keylist[i].name = strpool(keylist[i].name); printf( "ancc: another noobish C compiler.\n" " Aean, 2014 <*****@*****.**>\n" "ancc project is licensed under the terms of the MIT License. You should have " "recieved a copy of the license. If not, please visit <http://mit-license.org/>. " "\n\n" ); if (argc < 2) { char* p = argv[0]; while(*p)p++; while(p > argv[0] && *p!='\\')p--; if(*p=='\\')p++; printf( "ancc CLI Format:\n" "%s <sourcename>\n", p); return 0; } push_file(argv[1]); preprocess(); read_source(); lr1(); printf("%d errors, %d warnings\n", error_occured, warning_occured); return 0; }
int main(int argc, char *argv[]) { int ret, nglyphs; SDL_Window *window; SDL_Renderer *renderer; Scene scene; Glyph glyphs[NGLYPHS]; FILE *source; /* Initialize the TTF library */ if (TTF_Init() < 0) { fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError()); SDL_Quit(); exit(2); } if (argc == 1) nglyphs = read_source(stdin, glyphs, NGLYPHS); else { source = fopen(argv[1], "r"); if (source == NULL) { fprintf(stderr, "Cannot open file: %s\n", argv[1]); cleanup(2); } nglyphs = read_source(source, glyphs, NGLYPHS); fclose(source); } load_fonts(); if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { fprintf(stderr, "SDL_CreateWindowAndRenderer() failed: %s\n", SDL_GetError()); cleanup(2); } ret = render_text(renderer, &scene, glyphs, nglyphs); if (ret > 0) { close_fonts(); cleanup(ret); } draw_scene(renderer, &scene); ret = scene_loop(renderer, &scene); close_fonts(); cleanup(ret); return 0; }
static int emc_notifier_call(struct notifier_block *nb, unsigned long val, void *ptr) { read_source(&power_ctx.emc); check_clks(); return 0; }
int main (void) { FILE *f; mdl_t source_mdl; inp_t fake; fake.output.time_steps = 128; fake.solver.ti = 0.000001 * CONST_MKSA_YEAR; fake.solver.tf = 10000000 * CONST_MKSA_YEAR; int verbose = 0; /* Create the input.ini file */ f = fopen ("source.mdl", "w"); fprintf (f, "# This source model file was created by source_test\n"); fprintf (f, "# cell number, Av [mag], n(H) [cm^-3], Tgas [K], Tdust [K]\n"); fprintf (f, "0 0.1 1e+02 15.0 12.0\n"); fprintf (f, "1 1.0 1e+03 11.0 10.0\n"); fprintf (f, "2 10.0 1e+04 8.0 7.0\n"); fclose (f); /* Read it */ if( read_source ("source.mdl", &source_mdl, &fake, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } /* Check that the values are correct */ if ((source_mdl.n_cells == 3) && (source_mdl.cell[0].av[0] == 0.1) && (source_mdl.cell[0].nh[0] == 1e2) && (source_mdl.cell[0].tgas[0] == 15) && (source_mdl.cell[0].tdust[0] == 12) && (source_mdl.cell[1].av[0] == 1.0) && (source_mdl.cell[1].nh[0] == 1e3) && (source_mdl.cell[1].tgas[0] == 11) && (source_mdl.cell[1].tdust[0] == 10) && (source_mdl.cell[2].av[0] == 10.0) && (source_mdl.cell[2].nh[0] == 1e4) && (source_mdl.cell[2].tgas[0] == 8) && (source_mdl.cell[2].tdust[0] == 7) && (source_mdl.ts.time_steps[10] - 332.988055 < 0.0001) && (source_mdl.ts.time_steps[23] - 7130.784562 < 0.0001) && (source_mdl.ts.time_steps[47] - 2040939.960351 < 0.0001) ) { free_mdl(&source_mdl); return EXIT_SUCCESS; } else { free_mdl(&source_mdl); return EXIT_FAILURE; } }
void elfutils_setup_env(char *src, char *execf_in, char *execf_out, char *libc, int tape_len, eresi_Addr ifuncoffset, eresi_Addr dl_auxv, // offset of _dl_auxv (in ld.so's data) eresi_Addr endoffset, // offset of &end on stack from where auxv lives on stack (value of _dl_auxv) int debug, elf_bf_env_t *env) { elfsh_Dyn *dyn; // open and load exec env->e_bf_source = read_source(src); env->e_bf_sourcepath = src; env->e_exec.ee_ifunc_offset = ifuncoffset; env->e_exec.ee_dl_auxv = dl_auxv; env->e_exec.ee_end_offset = endoffset; env->e_exec.ee_for_debug = debug; env->e_bf_libc = libc; env->e_exec.ee_libc = libc; env->e_exec.ee_exec_path = execf_in; init_elf_bf_linkmap(&(env->e_exec.ee_lm), execf_in, execf_out); elfshsect_t *bs; //we will pretend this section is our string table bs = elfsh_get_section_by_name(env->e_exec.ee_lm.lm_f, ".bss", NULL, NULL, NULL); env->e_exec.ee_lm.lm_bss_index = bs->index; env->e_exec.ee_tape_len = tape_len; //env->e_exec.ee_reloc_end = exec_reloc_end; env->e_exec.ee_dt_rela = get_dynent_addr(env->e_exec.ee_lm.lm_f, DT_RELA); env->e_exec.ee_dt_relasz = get_dynent_addr(env->e_exec.ee_lm.lm_f, DT_RELASZ); env->e_exec.ee_dt_sym = get_dynent_addr(env->e_exec.ee_lm.lm_f, DT_SYMTAB); env->e_exec.ee_dt_jmprel = get_dynent_addr(env->e_exec.ee_lm.lm_f, DT_JMPREL); env->e_exec.ee_dt_pltrelsz = get_dynent_addr(env->e_exec.ee_lm.lm_f, DT_PLTRELSZ); env->e_exec.ee_ptr_tape_ptr = NULL; env->e_exec.ee_tape_ptr = NULL; env->e_exec.ee_ptr_tape_copy = NULL; env->e_exec.ee_lm.lm_ifunc = NULL; env->e_exec.ee_exec_map = NULL; env->e_exec.ee_ld_base = NULL; env->e_exec.ee_libc_base = NULL; env->e_exec.ee_stack_addr = NULL; env->e_exec.ee_lm.lm_getchar = NULL; env->e_exec.ee_lm.lm_putchar = NULL; env->e_exec.ee_lm.lm_putcharextra = NULL; env->e_exec.ee_exec_map_value = NULL; env->e_exec.ee_num_reloc = bf_rela_count(env); init_tape_syms(&(env->e_exec)); //first count number of new syms insert_exec_secs(&(env->e_exec)); init_tape_syms(&(env->e_exec)); fix_dynamic_table(&(env->e_exec)); }
Document createDocument(const boost::filesystem::path& file, const ParseParameters& params) { Platform xmlplat; xercesc::LocalFileInputSource source(String(file.generic_string())); xercesc::XercesDOMParser parser; setup_parser(parser, params); read_source(parser, source); return Document(parser.adoptDocument(), true); }
Document createDocument(const std::string& text, const ParseParameters& params, const std::string& id) { Platform xmlplat; xercesc::MemBufInputSource source(reinterpret_cast<const XMLByte *>(text.c_str()), static_cast<XMLSize_t>(text.size()), String(id)); xercesc::XercesDOMParser parser; setup_parser(parser, params); read_source(parser, source); return Document(parser.adoptDocument(), true); }
int main(int argc, char **argv) { FILE *in, *out = stdout; enum pp_flags flags = 0; struct preproc *pp; source_file_name = "samples/preproc.P"; in = fopen("samples/preproc.P", "r"); if (!in) error(1, errno, "fopen"); pp = read_source(in, flags); if (!pp) error(1, errno, "read_source"); // preprocess(pp); write_source(pp, out); free_preproc(pp); exit(0); }
int main(int argc, char *argv[]) { int n; float *values = NULL; performance_t *p = NULL; performance_t perf[] = { {"libc", vecexp_libc, 0., 0., 0, NULL}, {"Cephes", vecexp_cephes, 0., 0., 0, NULL}, /* {"Taylor 5th", vecexp_taylor5, 0., 0., 0, NULL}, */ /* {"Taylor 7th", vecexp_taylor7, 0., 0., 0, NULL}, */ /* {"Taylor 9th", vecexp_taylor9, 0., 0., 0, NULL}, */ /* {"Taylor 11th", vecexp_taylor11, 0., 0., 0, NULL}, */ /* {"Taylor 13th", vecexp_taylor13, 0., 0., 0, NULL}, */ /* {"Remez 5th [-0.5,+0.5]", vecexp_remez5_05_05, 0., 0., 0, NULL}, */ /* {"Remez 7th [-0.5,+0.5]", vecexp_remez7_05_05, 0., 0., 0, NULL}, */ /* {"Remez 9th [-0.5,+0.5]", vecexp_remez9_05_05, 0., 0., 0, NULL}, */ /* {"Remez 11th [-0.5,+0.5]", vecexp_remez11_05_05, 0., 0., 0, NULL}, */ /* {"Remez 13th [-0.5,+0.5]", vecexp_remez13_05_05, 0., 0., 0, NULL}, */ {"Remez 5th [0,log2]", remez5_0_log2, 0., 0., 0, NULL}, /* {"Remez 7th [0,log2]", remez7_0_log2, 0., 0., 0, NULL}, */ /* {"Remez 9th [0,log2]", remez9_0_log2, 0., 0., 0, NULL}, */ /* {"Remez 11th [0,log2]", remez11_0_log2, 0., 0., 0, NULL}, */ /* {"Remez 13th [0,log2]", remez13_0_log2, 0., 0., 0, NULL}, */ {NULL, NULL, 0., 0., 0}, }; FILE *fp = fopen("xxx", "r"); values = read_source(fp, &n); fclose(fp); measure(perf, values, n); for (p = perf;p->func != NULL;++p) { printf( "%s\t%f\t%e\t%e\n", p->name, p->elapsed_time / (float)CLOCKS_PER_SEC, p->error_peak, p->error_rms ); } return 0; }
MP4MetadataRust::MP4MetadataRust(Stream* aSource) : mSource(aSource) , mRustState(mp4parse_new()) { static LazyLogModule sLog("MP4Metadata"); std::vector<uint8_t> buffer; int32_t rv = read_source(mSource, buffer); if (rv == MP4PARSE_OK) { rv = mp4parse_read(mRustState.get(), buffer.data(), buffer.size()); } MOZ_LOG(sLog, LogLevel::Debug, ("rust parser returned %d\n", rv)); Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_SUCCESS, rv == MP4PARSE_OK); if (rv != MP4PARSE_OK) { MOZ_ASSERT(rv > 0); Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_ERROR_CODE, rv); } }
int main(int argc, char *argv[]) { int err= 0; /* return code */ char *outfile = (char *)0; /* --output-file */ char *errfile = (char *)0; /* --error-file */ char *headerfile = (char *)0; /* --texi-header-file */ char *yank_type = "*"; /* --yank-type */ char *body_env = "smallexample"; /* -B<environment> */ int page_width = 80; /* --page-width */ int tabsize = 8; /* --tab-size */ int tabs_to_spaces = 0; /* --tabs-to-spaces */ int output_type = 1; /* --output-type */ int table_of_contents = 0; /* --table-of-contents */ int sort_entries = 1; /* --preserve-order */ int texi_flags = TEXI_CREATE_HEADER | TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES; int adoc_flags = ADOC_FORM_FEEDS; int warn_mask = WARN_NORMAL; int scanner_flags = 0; /* --indented-comments */ /* --unindent-bodytext */ int minimum_indentation = -1; /* --reindent-bodytext */ /* handles for the macro tables */ int texi_macros = 0; int body_macros = 0; #ifdef _DCC /* Dice */ expand_args(argc,argv, &argc,&argv); #endif /* _DCC */ /* filenames on MS-DOG systems look very ugly: all uppercase and * backslashes. Perform some cosmetics */ #ifdef __MSDOS__ whoami= "adoc"; #else whoami= argv[0]; #endif /*__MSDOS__*/ /* set the debugging defaults */ D(bug_init(0,stdout)); /* initialize the default error stream */ ferr= stderr; if(err == 0) { /* prepare the texinfo macro table */ texi_macros= mactab_new( 4+10 ); if(!texi_macros) err= 1; } if(err == 0) { /* prepare the body-text macro table */ body_macros= mactab_new( 2 ); if(!body_macros) err= 2; } if(err) echo("error %d creating macro tables -- not enough memory?", err); else /* BEGIN scanning command line arguments */ while( (--argc > 0) && (err <= 0) ) { char *arg= *++argv; #ifdef DEBUG if(argc > 1) { D(bug("examining command line argument `%s' ( `%s', ... ) [%d]", argv[0], argv[1], argc-1)); } else { D(bug("examining command line argument `%s' ( ) [%d]", argv[0], argc-1)); } #endif /* DEBUG */ if(*arg=='-') { /* remember the original command-line option string */ char *opt= arg; if(arg[1]=='-') arg= convert_args(*argv); switch(*++arg) { /*-0*/ case '0': output_type= 0; break; /*-1*/ case '1': output_type= 1; break; /*-2*/ case '2': output_type= 2; tabs_to_spaces= 1; minimum_indentation= 0; break; /*-b*/ case 'b': texi_flags |= TEXI_TABLE_FUNCTIONS; break; /*-B*/ case 'B': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { body_env= arg; } else { echo("missing texinfo body text environment after %s option",opt); err= 1; } break; /*-c*/ case 'c': err= mactab_add(body_macros, "\\*", "/*", "*\\", "*/", (char *)0); if(err) echo("error %d adding comment convertion macros",err); break; /*-d*/ case 'd': #ifdef DEBUG if(arg[1]) { D(bug_level= atoi( &(arg[1]) )); } else { D(bug_level= 1); } #else /* !DEBUG */ echo("not compiled w/ -DDEBUG. No debug information available -- Sorry"); /* no error */ #endif /* DEBUG */ break; /*-D*/ case 'D': if(arg[1] && --argc > 0) { char *lhs= &arg[1]; char *rhs= *(++argv); err= mactab_add(texi_macros, lhs, rhs, (char *)0); if(err) echo("error adding texinfo macro `%s' = `%s'", lhs, rhs); } else { echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt); err= 1; } break; /*-E*/ case 'E': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { if(errfile) { echo("warning: option `%s' has already been seen", opt); D(bug("%s \"%s\" superseeds -E \"%s\"", opt, arg, errfile)); } /*errfile= strcmp(arg,"-") ? arg : (char *)0;*/ errfile= arg; } else /* !(arg && *arg) */ { echo("missing filename after `%s' option", opt); err= 1; } break; /*-f*/ case 'f': if(arg[1]) { while(*++arg) switch(*arg) { case 'f': adoc_flags |= ADOC_FORM_FEEDS; texi_flags |= TEXI_FUNCTION_NEWPAGE; break; default: echo("unknown paging option: `%s'",opt); break; } } else /* !arg[1] */ { adoc_flags &= ~ADOC_FORM_FEEDS; texi_flags &= ~TEXI_FUNCTION_NEWPAGE; } break; /*-g*/ case 'g': if(arg[1]) { while(*++arg) switch(*arg) { case 's': texi_flags |= TEXI_GROUP_SECTIONS; break; default: echo("unknown grouping option: `%s'",opt); err= 1; break; } } else texi_flags &= ~TEXI_GROUP_SECTIONS; break; /*-H*/ case 'H': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { if(headerfile) { echo("warning: option `%s' has already been seen", opt); D(bug("%s \"%s\" superseeds -H \"%s\"", opt, arg, headerfile)); } headerfile= arg; } else /* !(arg && *arg) */ { echo("missing texinfo header filename after `%s' option", opt); err= 1; } break; /*-h*/ case 'h': printf("usage: %s [options] [-o outfile] [@ listfile] [infiles...]\n\n", whoami); display_args( arg[1] ? atoi(&arg[1]) : 3 ); err= -1; /* negative means exit w/o error */ break; /*-I*/ case 'I': table_of_contents= 1; break; /*-i*/ case 'i': yank_type= "i"; break; /*-j*/ case 'j': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { if( (minimum_indentation= atoi(arg)) < 0 ) { echo("illegal indentation: %d (must be >= 0)", minimum_indentation); err= 1; } } else /* !(arg && *arg) */ { echo("missing indentation after `%s' option", opt); err= 1; } break; /*-l*/ case 'l': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { page_width= atoi(arg); if(page_width < 1) { echo("illegal page width: `%s' (must be > 0)", arg); err= 1; } } else /* !(arg && *arg) */ { echo("missing page width after `%s' option", opt); err= 1; } break; /*-M*/ case 'M': if(arg[1] && --argc > 0) { char *lhs= &arg[1]; char *rhs= *(++argv); err= mactab_add(body_macros, lhs, rhs, (char *)0); if(err) echo("error adding body macro `%s' -> `%s'", lhs, rhs); } else { echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt); err= 1; } break; /*-n*/ case 'n': output_type= 0; break; /*-o*/ case 'o': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { if(outfile) echo("warning: option `%s' has already been seen", opt); outfile= arg; } else /* !(arg && *arg) */ { echo("missing filename after `%s' option", opt); err= 1; } break; /*-p*/ case 'p': sort_entries= arg[1] ? 1:0; break; /*-q*/ case 'q': break; /*-T*/ case 'T': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { tabs_to_spaces= 1; tabsize= atoi(arg); if(tabsize < 1) { echo("illegal tab step: `%d' (must be >= 1)", tabsize); err= 1; } } else /* !(arg && *arg) */ { echo("missing tab size after `%s' option", opt); err= 1; } break; /*-t*/ case 't': tabs_to_spaces= arg[1] ? atoi(&arg[1]) : 1; break; /*-U*/ case 'U': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0; if(arg && *arg) { mactab_remove(texi_macros, arg, (char *)0); mactab_remove(body_macros, arg, (char *)0); } else /* !(arg && *arg) */ { echo("missing macro after `%s' option", opt); err= 1; } break; /*-u*/ case 'u': if(arg[1]) { scanner_flags &= ~SCANNER_UNINDENT_BODYTEXT; minimum_indentation= -1; } else scanner_flags |= SCANNER_UNINDENT_BODYTEXT; break; /*-v*/ case 'v': printf("ADOC Version " VERSION " (compiled " __DATE__ ", " __TIME__ ")\n" "(c)Copyright 1995 by Tobias Ferber, All Rights Reserved\n" ); err= -1; break; /*-W*/ case 'W': if(arg[1]) { ++arg; if( isdigit(*arg) ) warn_mask |= atoi(arg); else switch( strarg(arg, "none", /* 1 */ "arnings", /* 2 */ "keywords", /* 3 */ "absence", /* 4 */ "untitled", /* 5 */ "all", "") ) /* 6 */ { case 1: warn_mask = WARN_NONE; break; case 2: warn_mask |= WARN_NORMAL; break; case 3: warn_mask |= WARN_UNKNOWN_KEYWORDS; break; case 4: warn_mask |= WARN_MISSING_KEYWORDS; break; case 5: warn_mask |= WARN_UNTITLED_SECTION; break; case 6: warn_mask |= WARN_ALL; break; default: echo("unknown warning method: `%s'",opt); err= 1; break; } } else warn_mask= WARN_NONE; break; /*-x*/ case 'x': if(arg[1]) { switch( strarg(++arg, "off", /* 1 */ "on", /* 2 */ "itemize", /* 3 */ "", "") ) /* 4 */ { case 1: texi_flags &= ~TEXI_PARSE_REFERENCES; texi_flags &= ~TEXI_ITEMIZE_REFERENCES; break; case 2: texi_flags |= TEXI_PARSE_REFERENCES; texi_flags &= ~TEXI_ITEMIZE_REFERENCES; break; case 3: texi_flags |= TEXI_PARSE_REFERENCES; texi_flags |= TEXI_ITEMIZE_REFERENCES; break; default: echo("unknown reference handlig option: `%s'",opt); err= 1; break; } } else texi_flags &= ~(TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES); break; /*-Y*/ case 'Y': if(arg[1]) scanner_flags &= ~SCANNER_ALLOW_INDENTED_COMMENTS; else scanner_flags |= SCANNER_ALLOW_INDENTED_COMMENTS; break; /*-y*/ case 'y': if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0L; if(arg && *arg) yank_type= arg; else /* !(arg && *arg) */ { echo("missing comment type string after `%s' option", opt); err= 1; } break; /*-z*/ case 'z': texi_flags &= ~TEXI_CREATE_HEADER; break; /*-Z*/ case 'Z': if(arg[1]) texi_flags &= ~TEXI_NO_INDEX; else texi_flags |= TEXI_NO_INDEX; break; /* * The following options are ignored for compatibility * with Bill Koester's original version `autodoc' which * is part of C=ommodore's Native Developer Kit (NDK). */ /*-C*/ case 'C': /*-F*/ case 'F': /*-s*/ case 's': /*-a*/ case 'a': /*-r*/ case 'r': /*-w*/ case 'w': echo("warning: option `%s' ignored for compatibility", opt); break; /*- */ case '\0': if( (err= flist_addfile("")) ) echo("out of memory... hmmmmmmmmmpf!"); break; /*??*/ default: echo("unrecognized option `%s'", opt); err= 1; break; } } else if(*arg=='@') { if(arg[1]) ++arg; else arg= (--argc > 0) ? *(++argv) : (char *)0L; if(arg && *arg) { if( (err= flist_from_file(arg)) ) echo("out of memory... aaarrrrrrgggggghh!"); } else /* !(arg && *arg) */ { echo("missing filename after `%s'", *argv); err= 1; } } else /* *arg != '@' */ { if(arg && *arg) { if( (err= flist_addfile(arg)) ) echo("out of memory... aaaiiiiiieeeeeeeee!"); } else echo("internal problem parsing command line arguments: arg is empty"); } } /* END scanning command line arguments */ D(bug("command line argument parsing done")); if(err == 0) { /* prepare the error stream */ if(errfile && *errfile) { D(bug("opening error stream `%s'",errfile)); if( !(ferr= fopen(errfile,"w")) ) { echo("could not write error messages to `%s'",errfile); err= __LINE__; } } /*else ferr is initialized to stderr */ /* if no filename is given then read from stdin */ if( !flist_getname() ) flist_addfile(""); /* read the input files (the scanner takes them from the flist queue) */ D(bug("reading autodocs of type `%s'", yank_type)); if(err == 0) err= read_source(yank_type, warn_mask, scanner_flags); if(err < 0) err= -err; /* I/O error */ D(bug("disposing file list")); flist_dispose(); /* */ if( (err == 0) && (minimum_indentation >= 0) ) { if( (err= funindent(minimum_indentation, tabsize)) ) echo("error %d reworking body text indentation -- not enough memory?",err); /* funindent() already performed that conversion */ else tabs_to_spaces= 0; } if( (err == 0) && (output_type > 0) ) { FILE *fout; /* prepare the output file */ if(outfile && *outfile) { D(bug("opening output stream `%s'",outfile)); if(!(fout= fopen(outfile,"w")) ) { echo("could not write to `%s'",outfile); err= __LINE__; } } else fout= stdout; if( fout && (err==0) ) { if(sort_entries) { D(bug("sorting entries")); funsort(); } switch(output_type) { case 1: /* --autodoc */ if(table_of_contents) { D(bug("writing table of contents")); err= gen_autodoc_toc(fout); } if(err == 0) { D(bug("writing autodocs")); err= gen_autodoc( fout, page_width, tabs_to_spaces ? tabsize : 0, adoc_flags, mactab(body_macros) ); } break; case 2: /* --texinfo */ if(texi_flags & TEXI_CREATE_HEADER) { D(bug("creating texinfo header")); err= gen_texinfo_header( fout, headerfile, mactab(texi_macros) ); } if(err == 0) { D(bug("adding texinfo body macros")); err= mactab_add( body_macros, "@", "@@", "{", "@{", "}", "@}", /* "...", "@dots{}", */ /* "TeX", "@TeX{}", */ "e.g. ", "e.g.@: ", "E.g. ", "E.g.@: ", "i.e. ", "i.e.@: ", "I.e. ", "I.e.@: ", (char *)0 ); } if(err == 0) { D(bug("creating texinfo output")); err+= gen_texinfo( fout, tabs_to_spaces ? tabsize : 0, texi_flags, body_env, mactab(body_macros) ); } if(err) echo("error creating texinfo output"); break; default: /* --dry-run */ break; } } if(fout && (fout != stdout)) fclose(fout); } D(bug("disposing libfun entries")); funfree(); } #ifdef DEBUG mactab_debug(bug_stream); #endif D(bug("disposing macro tables")); mactab_dispose(body_macros); mactab_dispose(texi_macros); /* */ if(err > 0) { echo("[%s] *** Error %d", (outfile && *outfile) ? outfile : "stdout", err); fprintf(ferr,"%s terminated abnormally (error %d)\n", whoami, err); } D(bug("closing I/O streams")); if( ferr && (ferr != stderr) && (ferr != stdout) ) fclose(ferr); D(bug("exiting adoc returning %d (%s)", (err>0) ? 1:0, (err>0) ? "error":"success" )); D(bug_exit()); #ifdef DEBUG if(bug_stream && (bug_stream != stdout)) fclose(bug_stream); #endif /*DEBUG*/ return (err > 0) ? 1:0; }
int main (int argc, char *argv[]) { inp_t input_params; mdl_t source_mdl; net_t network; int cell_index; int verbose = 1; char *input_file; /* Parse options and command line arguments. Diplay help message if no (or more than one) argument is given. */ { int opt; static struct option longopts[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"verbose", no_argument, NULL, 'v'}, {"quiet", no_argument, NULL, 'q'}, {0, 0, 0, 0} }; while ((opt = getopt_long (argc, argv, "hVvq", longopts, NULL)) != -1) { switch (opt) { case 'h': usage (); return EXIT_SUCCESS; break; case 'V': version (); return EXIT_SUCCESS; break; case 'v': verbose = 2; break; case 'q': verbose = 0; break; default: usage (); return EXIT_FAILURE; } }; argc -= optind; argv += optind; if (argc != 1) { usage (); return EXIT_FAILURE; } input_file = argv[0]; } /* Read the input file */ if( read_input_file_names (input_file, &input_params.files, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } /* Read the chemical network file */ if( read_network (input_params.files.chem_file, &network, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } /* Read the input file */ if( read_input (input_file, &input_params, &network, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } /* Read the source model file */ if( read_source (input_params.files.source_file, &source_mdl, &input_params, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } // Hdf5 files, datatype and dataspace hid_t fid, datatype, dataspace, dataset, tsDataset, tsDataspace, speciesDataset, speciesDataspace, speciesType; datatype = H5Tcopy(H5T_NATIVE_DOUBLE); hsize_t dimsf[ ROUTE_DATASET_RANK ]={ source_mdl.n_cells, source_mdl.ts.n_time_steps, input_params.output.n_output_species, N_OUTPUT_ROUTES }; fid = H5Fcreate( "astrochem_output.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); dataspace = H5Screate_simple( ABUNDANCE_DATASET_RANK, dimsf, NULL); // Add Atributes hid_t simpleDataspace = H5Screate(H5S_SCALAR); hid_t attrType = H5Tcopy(H5T_C_S1); H5Tset_size ( attrType, MAX_CHAR_FILENAME ); H5Tset_strpad(attrType,H5T_STR_NULLTERM); hid_t attrNetwork = H5Acreate( fid, "chem_file", attrType, simpleDataspace, H5P_DEFAULT, H5P_DEFAULT); H5Awrite( attrNetwork, attrType, realpath( input_params.files.chem_file, NULL ) ); H5Aclose( attrNetwork ); hid_t attrModel = H5Acreate( fid, "source_file", attrType, simpleDataspace, H5P_DEFAULT, H5P_DEFAULT); H5Awrite( attrModel, attrType, realpath( input_params.files.source_file, NULL ) ); H5Aclose( attrModel ); H5Tclose( attrType ); H5Sclose( simpleDataspace ); // Define chunk property hsize_t chunk_dims[ ROUTE_DATASET_RANK ] = { 1, 1, input_params.output.n_output_species, N_OUTPUT_ROUTES }; hid_t prop_id = H5Pcreate(H5P_DATASET_CREATE); H5Pset_chunk(prop_id, ABUNDANCE_DATASET_RANK , chunk_dims); // Create dataset dataset = H5Dcreate(fid, "Abundances", datatype, dataspace, H5P_DEFAULT, prop_id, H5P_DEFAULT); int i; hid_t dataspaceRoute, route_t_datatype, r_t_datatype, route_prop_id, routeGroup; hid_t routeDatasets[ input_params.output.n_output_species ]; if (input_params.output.trace_routes) { // Create route dataspace dataspaceRoute = H5Screate_simple( ROUTE_DATASET_RANK, dimsf, NULL); // Create route datatype r_t_datatype = H5Tcreate (H5T_COMPOUND, sizeof(r_t)); H5Tinsert( r_t_datatype, "reaction_number", HOFFSET(r_t, reaction_no ), H5T_NATIVE_INT); H5Tinsert( r_t_datatype, "reaction_rate", HOFFSET(r_t, rate), H5T_NATIVE_DOUBLE); route_t_datatype = H5Tcreate (H5T_COMPOUND, sizeof(rout_t)); H5Tinsert( route_t_datatype, "formation_rate", HOFFSET(rout_t, formation ), r_t_datatype ); H5Tinsert( route_t_datatype, "destruction_rate", HOFFSET(rout_t, destruction ), r_t_datatype ); // Define route chunk property route_prop_id = H5Pcreate(H5P_DATASET_CREATE); H5Pset_chunk( route_prop_id, ROUTE_DATASET_RANK, chunk_dims); // Create each named route dataset routeGroup = H5Gcreate( fid, "Routes", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ); char routeName[6] = "route_"; char tempName[ MAX_CHAR_SPECIES + sizeof( routeName ) ]; for( i = 0; i < input_params.output.n_output_species ; i++ ) { strcpy( tempName, routeName ); strcat( tempName, network.species[input_params.output.output_species_idx[i]].name ); routeDatasets[i] = H5Dcreate( routeGroup, tempName, route_t_datatype, dataspaceRoute, H5P_DEFAULT, route_prop_id, H5P_DEFAULT); } } // Timesteps and species hsize_t n_ts = source_mdl.ts.n_time_steps; hsize_t n_species = input_params.output.n_output_species ; tsDataspace = H5Screate_simple( 1, &n_ts, NULL); speciesDataspace = H5Screate_simple( 1, &n_species, NULL); speciesType = H5Tcopy (H5T_C_S1); H5Tset_size (speciesType, MAX_CHAR_SPECIES ); H5Tset_strpad(speciesType,H5T_STR_NULLTERM); // Create ts and species datasets tsDataset = H5Dcreate(fid, "TimeSteps", datatype, tsDataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); speciesDataset = H5Dcreate(fid, "Species", speciesType, speciesDataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); double* convTs = (double*) malloc( sizeof(double)* source_mdl.ts.n_time_steps ); for( i=0; i< source_mdl.ts.n_time_steps; i++ ) { convTs[i] = source_mdl.ts.time_steps[i] / CONST_MKSA_YEAR; } H5Dwrite( tsDataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, convTs ); char speciesName [ input_params.output.n_output_species ][ MAX_CHAR_SPECIES ]; for( i = 0; i < input_params.output.n_output_species ; i++ ) { strcpy( speciesName[i], network.species[input_params.output.output_species_idx[i]].name ); } H5Dwrite( speciesDataset, speciesType, H5S_ALL, H5S_ALL, H5P_DEFAULT, speciesName ); free( convTs ); H5Dclose( tsDataset ); H5Dclose( speciesDataset ); H5Tclose( speciesType ); H5Sclose( tsDataspace ); H5Sclose( speciesDataspace ); #ifdef HAVE_OPENMP /*Initialize lock*/ omp_init_lock(&lock); /* Solve the ODE system for each cell. */ { #pragma omp parallel for schedule (dynamic, 1) #endif for (cell_index = 0; cell_index < source_mdl.n_cells; cell_index++) { if (verbose >= 1) fprintf (stdout, "Computing abundances in cell %d...\n", cell_index); if( full_solve ( fid, dataset, routeDatasets, dataspace, dataspaceRoute, datatype, route_t_datatype, cell_index, &input_params, source_mdl.mode, &source_mdl.cell[cell_index], &network, &source_mdl.ts, verbose) != EXIT_SUCCESS ) { exit (EXIT_FAILURE); } if (verbose >= 1) fprintf (stdout, "Done with cell %d.\n", cell_index); } #ifdef HAVE_OPENMP } /*Finished lock mechanism, destroy it*/ omp_destroy_lock(&lock); #endif /* * Close/release hdf5 resources. */ if (input_params.output.trace_routes) { for( i = 0; i < input_params.output.n_output_species ; i++ ) { H5Dclose(routeDatasets[i] ); } H5Sclose(dataspaceRoute); H5Gclose(routeGroup); H5Pclose(route_prop_id); H5Tclose(r_t_datatype); H5Tclose(route_t_datatype); } H5Dclose(dataset); H5Pclose(prop_id); H5Sclose(dataspace); H5Tclose(datatype); H5Fclose(fid); free_input (&input_params); free_mdl (&source_mdl); free_network (&network); return (EXIT_SUCCESS); }
int main (void) { FILE *f; mdl_t source_mdl; inp_t fake; int verbose = 0; /* Create the input.ini file */ f = fopen ("source_dyn.mdl", "w"); fprintf (f, "# Source model file example for a time-dependant source structure\n" "[times]\n" " 0 1.00e-06\n" " 1 1.24e-06\n" " 2 1.55e-06\n" " 3 1.92e-06\n" " 4 2.39e-06\n" " 5 2.97e-06\n" " 6 3.69e-06\n" " 7 4.59e-06\n" " 8 5.70e-06\n" " 9 7.09e-06\n" " 10 8.81e-06\n" "[cells]\n" "# cell (= shell) number, time index, Av [mag], nH [cm^-3], Tgas [K], Tdust [K]\n" " 0 0 0.00 1.00e+04 10.00 10.00\n" " 0 1 0.16 1.11e+04 11.50 11.50\n" " 0 2 0.31 1.24e+04 12.99 12.99\n" " 0 3 0.47 1.39e+04 14.49 14.49\n" " 0 4 0.63 1.55e+04 15.98 15.98\n" " 0 5 0.79 1.72e+04 17.48 17.48\n" " 0 6 0.94 1.92e+04 18.98 18.98\n" " 0 7 1.10 2.14e+04 20.47 20.47\n" " 0 8 1.26 2.39e+04 21.97 21.97\n" " 0 9 1.42 2.66e+04 23.46 23.46\n" " 0 10 1.57 2.97e+04 24.96 24.96\n" " 1 0 0.00 1.00e+04 10.00 10.00\n" " 1 1 0.16 1.11e+04 11.50 11.50\n" " 1 2 0.31 1.24e+04 12.99 12.99\n" " 1 3 0.47 1.39e+04 14.49 14.49\n" " 1 4 0.63 1.55e+04 15.98 15.98\n" " 1 5 0.79 1.72e+04 17.48 17.48\n" " 1 6 0.94 1.92e+04 18.98 18.98\n" " 1 7 1.10 2.14e+04 20.47 20.47\n" " 1 8 1.26 2.39e+04 21.97 21.97\n" " 1 9 1.42 2.66e+04 23.46 23.46\n" " 1 10 1.57 2.97e+04 24.96 24.96\n" " 2 0 0.00 1.00e+04 10.00 10.00\n" " 2 1 0.16 1.11e+04 11.50 11.50\n" " 2 2 0.31 1.24e+04 12.99 12.99\n" " 2 3 0.47 1.39e+04 14.49 14.49\n" " 2 4 0.63 1.55e+04 15.98 15.98\n" " 2 5 0.79 1.72e+04 17.48 17.48\n" " 2 6 0.94 1.92e+04 18.98 18.98\n" " 2 7 1.10 2.14e+04 20.47 20.47\n" " 2 8 1.26 2.39e+04 21.97 21.97\n" " 2 9 1.42 2.66e+04 23.46 23.46\n" " 2 10 1.57 2.97e+04 24.96 24.96\n"); fclose (f); /* Read it */ if( read_source ("./source_dyn.mdl", &source_mdl, &fake, verbose) != EXIT_SUCCESS ) { return EXIT_FAILURE; } /* Check that the values are correct */ if ((source_mdl.n_cells == 3) && (source_mdl.ts.n_time_steps == 11) && (source_mdl.cell[0].av[0] == 0.0) && (source_mdl.cell[0].nh[0] == 1e4) && (source_mdl.cell[0].tgas[0] == 10) && (source_mdl.cell[0].tdust[0] == 10) && (source_mdl.cell[1].av[5] == 0.79) && (source_mdl.cell[1].nh[5] == 1.72e4) && (source_mdl.cell[1].tgas[5] == 17.48) && (source_mdl.cell[1].tdust[5] == 17.48) && (source_mdl.cell[2].av[10] == 1.57) && (source_mdl.cell[2].nh[10] == 2.97e4) && (source_mdl.cell[2].tgas[10] == 24.96) && (source_mdl.cell[2].tdust[10] == 24.96) && (source_mdl.ts.time_steps[5] / CONST_MKSA_YEAR - 2.97e-6 < 0.01e-6 )) { free_mdl(&source_mdl); return EXIT_SUCCESS; } else { free_mdl(&source_mdl); return EXIT_FAILURE; } }
void shader::load() { read_source(); compile_shader(); }
int main() { cl_int status; srand(time(NULL)); cl_platform_id platform; CHECK_STATUS(clGetPlatformIDs(1, &platform, NULL)); cl_device_id device; CHECK_STATUS(clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL)); cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, &status); CHECK_STATUS(status); cl_command_queue queue = clCreateCommandQueue(context, device, 0, &status); CHECK_STATUS(status); char* source = read_source("find_minimum.cl"); cl_program program = clCreateProgramWithSource(context, 1, (const char**)&source, NULL, NULL); CHECK_STATUS(status); free(source); CHECK_STATUS(clBuildProgram(program, 0, NULL, NULL, NULL, NULL)); cl_kernel kernel = clCreateKernel(program, "find_minimum", &status); CHECK_STATUS(status); cl_float values[NUM_VALUES]; random_fill(values, NUM_VALUES); cl_mem valuesBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float) * NUM_VALUES, values, &status); CHECK_STATUS(status); cl_mem resultBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(cl_float), NULL, &status); CHECK_STATUS(status); CHECK_STATUS(clSetKernelArg(kernel, 0, sizeof(cl_mem), &valuesBuffer)); CHECK_STATUS(clSetKernelArg(kernel, 1, sizeof(cl_mem), &resultBuffer)); // START:allocatelocal CHECK_STATUS(clSetKernelArg(kernel, 2, sizeof(cl_float) * NUM_VALUES, NULL)); // END:allocatelocal size_t work_units[] = {NUM_VALUES}; CHECK_STATUS(clEnqueueNDRangeKernel(queue, kernel, 1, NULL, work_units, work_units, 0, NULL, NULL)); cl_float result; CHECK_STATUS(clEnqueueReadBuffer(queue, resultBuffer, CL_TRUE, 0, sizeof(cl_float), &result, 0, NULL, NULL)); CHECK_STATUS(clReleaseMemObject(resultBuffer)); CHECK_STATUS(clReleaseMemObject(valuesBuffer)); CHECK_STATUS(clReleaseKernel(kernel)); CHECK_STATUS(clReleaseProgram(program)); CHECK_STATUS(clReleaseCommandQueue(queue)); CHECK_STATUS(clReleaseContext(context)); // START:sequential cl_float acc = FLT_MAX; for (int i = 0; i < NUM_VALUES; ++i) acc = fmin(acc, values[i]); // END:sequential if (acc != result) fprintf(stderr, "Error: %f != %f", acc, result); return 0; }
int main() { cl_int status; cl_platform_id platform; CHECK_STATUS(clGetPlatformIDs(1, &platform, NULL)); cl_device_id device; CHECK_STATUS(clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL)); cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, &status); CHECK_STATUS(status); cl_command_queue queue = clCreateCommandQueue(context, device, 0, &status); CHECK_STATUS(status); char* source = read_source("multiply_arrays.cl"); cl_program program = clCreateProgramWithSource(context, 1, (const char**)&source, NULL, NULL); CHECK_STATUS(status); free(source); CHECK_STATUS(clBuildProgram(program, 0, NULL, NULL, NULL, NULL)); cl_kernel kernel = clCreateKernel(program, "multiply_arrays", &status); CHECK_STATUS(status); cl_float a[1024], b[1024]; random_fill(a, 1024); random_fill(b, 1024); cl_mem inputA = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float) * 1024, a, &status); CHECK_STATUS(status); cl_mem inputB = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float) * 1024, b, &status); CHECK_STATUS(status); cl_mem output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(cl_float) * 1024, NULL, &status); CHECK_STATUS(status); CHECK_STATUS(clSetKernelArg(kernel, 0, sizeof(cl_mem), &inputA)); CHECK_STATUS(clSetKernelArg(kernel, 1, sizeof(cl_mem), &inputB)); CHECK_STATUS(clSetKernelArg(kernel, 2, sizeof(cl_mem), &output)); size_t work_units = 1024; CHECK_STATUS(clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &work_units, NULL, 0, NULL, NULL)); cl_float results[1024]; CHECK_STATUS(clEnqueueReadBuffer(queue, output, CL_TRUE, 0, sizeof(cl_float) * 1024, results, 0, NULL, NULL)); CHECK_STATUS(clReleaseMemObject(inputA)); CHECK_STATUS(clReleaseMemObject(inputB)); CHECK_STATUS(clReleaseMemObject(output)); CHECK_STATUS(clReleaseKernel(kernel)); CHECK_STATUS(clReleaseProgram(program)); CHECK_STATUS(clReleaseCommandQueue(queue)); CHECK_STATUS(clReleaseContext(context)); for (int i = 0; i < 1024; ++i) { printf("%f * %f = %f\n", a[i], b[i], results[i]); } return 0; }
int main() { // START:context cl_platform_id platform; clGetPlatformIDs(1, &platform, NULL); cl_device_id device; clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL); cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, NULL); // END:context // START:queue cl_command_queue queue = clCreateCommandQueue(context, device, 0, NULL); // END:queue // START:kernel char* source = read_source("multiply_arrays.cl"); cl_program program = clCreateProgramWithSource(context, 1, (const char**)&source, NULL, NULL); free(source); clBuildProgram(program, 0, NULL, NULL, NULL, NULL); cl_kernel kernel = clCreateKernel(program, "multiply_arrays", NULL); // END:kernel // START:buffers cl_float a[NUM_ELEMENTS], b[NUM_ELEMENTS]; random_fill(a, NUM_ELEMENTS); random_fill(b, NUM_ELEMENTS); cl_mem inputA = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float) * NUM_ELEMENTS, a, NULL); cl_mem inputB = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float) * NUM_ELEMENTS, b, NULL); cl_mem output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(cl_float) * NUM_ELEMENTS, NULL, NULL); // END:buffers // START:execute clSetKernelArg(kernel, 0, sizeof(cl_mem), &inputA); clSetKernelArg(kernel, 1, sizeof(cl_mem), &inputB); clSetKernelArg(kernel, 2, sizeof(cl_mem), &output); size_t work_units = NUM_ELEMENTS; clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &work_units, NULL, 0, NULL, NULL); // END:execute // START:results cl_float results[NUM_ELEMENTS]; clEnqueueReadBuffer(queue, output, CL_TRUE, 0, sizeof(cl_float) * NUM_ELEMENTS, results, 0, NULL, NULL); // END:results // START:cleanup clReleaseMemObject(inputA); clReleaseMemObject(inputB); clReleaseMemObject(output); clReleaseKernel(kernel); clReleaseProgram(program); clReleaseCommandQueue(queue); clReleaseContext(context); // END:cleanup for (int i = 0; i < NUM_ELEMENTS; ++i) { printf("%f * %f = %f\n", a[i], b[i], results[i]); } return 0; }
// create shader program from vertex and fragment components, either one is // optional GLuint gl_create_program(char *vertex_file, char *fragment_file, char *name) { GLint status = GL_FALSE; GLuint program = glCreateProgram(); GLuint vshader, fshader; if(vertex_file) { char *vs = read_source(vertex_file); if(vs == 0) { glDeleteProgram(program); return 0; } vshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vshader, 1, &vs, NULL); driver_free(vs); glCompileShader(vshader); printShaderInfoLog(vshader, "vertex"); glAttachShader(program, vshader); } if(fragment_file) { char *fs = read_source(fragment_file); if(fs == 0) { if(vertex_file) glDeleteShader(vshader); glDeleteProgram(program); return 0; } fshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fshader, 1, &fs, NULL); driver_free(fs); glCompileShader(fshader); printShaderInfoLog(fshader, "fragment"); glAttachShader(program, fshader); } glLinkProgram(program); printProgramInfoLog(program, name); glGetProgramiv(program, GL_LINK_STATUS, &status); if(status != GL_TRUE) { if(vertex_file) glDeleteShader(vshader); if(fragment_file) glDeleteShader(fshader); glDeleteProgram(program); return 0; } return program; }
static void read_all_sources(struct pt_regs *regs, struct task_struct *task) { u32 state, extra_data = 0; int i, vec_idx = 0, bt_size = 0; int nr_events = 0, nr_positive_events = 0; struct pt_regs *user_regs; struct quadd_iovec vec[5]; struct hrt_event_value events[QUADD_MAX_COUNTERS]; u32 events_extra[QUADD_MAX_COUNTERS]; struct quadd_record_data record_data; struct quadd_sample_data *s = &record_data.sample; struct quadd_ctx *ctx = hrt.quadd_ctx; struct quadd_cpu_context *cpu_ctx = this_cpu_ptr(hrt.cpu_ctx); struct quadd_callchain *cc = &cpu_ctx->cc; if (!regs) return; if (atomic_read(&cpu_ctx->nr_active) == 0) return; if (!task) task = current; rcu_read_lock(); if (!task_nsproxy(task)) { rcu_read_unlock(); return; } rcu_read_unlock(); if (ctx->pmu && ctx->pmu_info.active) nr_events += read_source(ctx->pmu, regs, events, QUADD_MAX_COUNTERS); if (ctx->pl310 && ctx->pl310_info.active) nr_events += read_source(ctx->pl310, regs, events + nr_events, QUADD_MAX_COUNTERS - nr_events); if (!nr_events) return; if (user_mode(regs)) user_regs = regs; else user_regs = current_pt_regs(); if (get_sample_data(s, regs, task)) return; vec[vec_idx].base = &extra_data; vec[vec_idx].len = sizeof(extra_data); vec_idx++; s->reserved = 0; if (ctx->param.backtrace) { cc->unw_method = hrt.unw_method; bt_size = quadd_get_user_callchain(user_regs, cc, ctx, task); if (!bt_size && !user_mode(regs)) { unsigned long pc = instruction_pointer(user_regs); cc->nr = 0; #ifdef CONFIG_ARM64 cc->cs_64 = compat_user_mode(user_regs) ? 0 : 1; #else cc->cs_64 = 0; #endif bt_size += quadd_callchain_store(cc, pc, QUADD_UNW_TYPE_KCTX); } if (bt_size > 0) { int ip_size = cc->cs_64 ? sizeof(u64) : sizeof(u32); int nr_types = DIV_ROUND_UP(bt_size, 8); vec[vec_idx].base = cc->cs_64 ? (void *)cc->ip_64 : (void *)cc->ip_32; vec[vec_idx].len = bt_size * ip_size; vec_idx++; vec[vec_idx].base = cc->types; vec[vec_idx].len = nr_types * sizeof(cc->types[0]); vec_idx++; if (cc->cs_64) extra_data |= QUADD_SED_IP64; } extra_data |= cc->unw_method << QUADD_SED_UNW_METHOD_SHIFT; s->reserved |= cc->unw_rc << QUADD_SAMPLE_URC_SHIFT; } s->callchain_nr = bt_size; record_data.record_type = QUADD_RECORD_TYPE_SAMPLE; s->events_flags = 0; for (i = 0; i < nr_events; i++) { u32 value = events[i].value; if (value > 0) { s->events_flags |= 1 << i; events_extra[nr_positive_events++] = value; } } if (nr_positive_events == 0) return; vec[vec_idx].base = events_extra; vec[vec_idx].len = nr_positive_events * sizeof(events_extra[0]); vec_idx++; state = task->state; if (state) { s->state = 1; vec[vec_idx].base = &state; vec[vec_idx].len = sizeof(state); vec_idx++; } else { s->state = 0; } quadd_put_sample(&record_data, vec, vec_idx); }